need help in updating gridview [Resolved]

Posted by Rickeybglr under ASP.NET on 8/8/2012 | Points: 10 | Views : 1554 | Status : [Member] | Replies : 5
i have a gridview which is fill up by store procedure select command.
now i have added two update buttons in gridview using item template. 'Approve 'or 'Reject'. when user click on the buttons respective SP shud get call which can update the DB.
my quest. is tht where call the two different SPs for those button




Responses

Posted by: Ranjeet_8 on: 8/8/2012 [Member] [MVP] Gold | Points: 50

Up
0
Down

Resolved
Try this
        <asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None"

AutoGenerateColumns="false" OnRowCommand="GridView1_RowCommand">
<Columns>
<asp:TemplateField HeaderText="Approved">
<ItemTemplate>
<asp:LinkButton ID="lnkApproved" runat="server" Text="Approved" CommandName="Approved" CommandArgument='<%#Eval("EmpID") %>'/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Reject">
<ItemTemplate>
<asp:LinkButton ID="lnkReject" runat="server" Text="Reject" CommandName="Reject" CommandArgument='<%#Eval("EmpID") %>'/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Column Header">
<ItemTemplate>
<%# Eval("Column_Name") %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Column Header">
<ItemTemplate>
<%# Eval("Column_Name")%>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)

{
string Emp_ID = e.CommandArgument.ToString();

if (e.CommandName.ToString() == "Reject")
{
// Call Reject Stored Procedure

}
else if(e.CommandName.ToString() == "Approved")
{
// Call Approved Stored Procedure

}
}


Rickeybglr, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rickeybglr on: 8/8/2012 [Member] Starter | Points: 25

Up
0
Down
thnk u so much

Rickeybglr, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Oswaldlily on: 8/8/2012 [Member] Starter | Points: 25

Up
0
Down
In storedprocedure pass extraparameter like this
Alter procedure spname
(
,
,
@flag as nvarchar(1)
)

if(@flag=='A')
{
//approve coding here

}
if(@flag=='R')
{
//Reject coding here

}



In codebehind while calling sp for approve
function.spname( , , 'A')=> will call approve
function.spname( , , 'R')=> will call Reject

Rickeybglr, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Messyleon on: 8/10/2012 [Member] Starter | Points: 25

Up
0
Down
ListView control displays data items as a list. You may want to update GridView to ensure that your records are up-to-date. GridView provides you "Command Field Buttons" that are built-in to the system. You can use these buttons update your GridView data. Note that you may require administrative rights to perform this task.
http://www.dapfor.com/en/net-suite/net-grid/tutorial/data-grouping

Rickeybglr, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rickeybglr on: 8/10/2012 [Member] Starter | Points: 25

Up
0
Down
Thanks for posting, my issue is resolved ...thnk u ..

Rickeybglr, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response