ASP.NET - how to get the Gridview cell (label) value in Gridview rowupdating event?

Asked By aileni giri on 30-Jun-12 07:42 AM
<asp:GridView run="server" cssclass="gridviewstyle">
<columns>
 <asp:TemplateField HeaderText="Invoice Amount">
                <ItemTemplate>
                  <asp:Label ID="lblInvoiceAmount" Text='<%#Eval("InvoiceAmount") %>' runat="server">          
</asp:Label>
                </ItemTemplate>
               <ItemStyle CssClass="gridviewitemstyle" />
              </asp:TemplateField>
              
              <asp:TemplateField HeaderText="Service Tax(@12.36%)">
                <ItemTemplate>
                  <asp:Label ID="lbltotalservicetaxamount" Text='<%#Eval("totalservicetaxamount") %>'
                    runat="server"></asp:Label>
                </ItemTemplate>
               <ItemStyle CssClass="gridviewitemstyle" />
              </asp:TemplateField>
              
              <asp:TemplateField HeaderText="Total Amount">
                <ItemTemplate>
                    <asp:Label ID="lbltotalamount" Text='<%#Eval("totalamount") %>' runat="server"></asp:Label>
                </ItemTemplate>
               <ItemStyle CssClass="gridviewitemstyle" />
              </asp:TemplateField>

</columns>
</GridView>

......................................................
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
 {
      prob:  here i  want  to get the above underlined  label  ..please  help me out...
}


Vikram Singh Saini replied to aileni giri on 30-Jun-12 08:02 AM
Try the following code:

protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
      GridViewRow gr = GridviewPersondays.Rows[e.RowIndex];

      Label lbl =  (Label)gr.FindControl("lbltotalamount");
    }
dipa ahuja replied to aileni giri on 30-Jun-12 04:24 PM
Step 1: Every server-side method that is called from the client-side, must be declared as "static", and also has to be decorated with the [System.Web.Services.WebMethod] tag.
 
[System.Web.Services.WebMethod()]
public static string Message()
{
  return "Hello from the server-side World!";
}
 
 
Step 2: Modifying the ScriptManager The "EnablePageMethods" attribute has to be added on the ScriptManager tag.
 
<asp:ScriptManager ID="ScriptManager1" runat="server"EnablePageMethods="true" />

 
Step 3:Adding a simple HTML button
 
<input onclick="GetMessage()" type="submit" value="Get Message" />

 
Step 4. Adding the JavaScript code
 
function GetMessage() {
  PageMethods.Message(OnGetMessageSuccess, OnGetMessageFailure);
}
 
The "OnGetMessageSuccess" is the name of the JavaScript function that will be called if the request is successful. Whereas the "OnGetMessageFailure" will be called if an exception is thrown.
 
function OnGetMessageSuccess(result, userContext, methodName) {
  alert(result);
}
 
function OnGetMessageFailure(error, userContext, methodName) {
  alert(error.get_message());
}