Monday, October 1, 2018

Gridview Linkbutton Event without using SelectedIndexChanged Event

Setting following Property in Gridview 

 <asp:GridView ID="dgvGrid" runat="server"  CssClass="mydatagrid" HeaderStyle-

   BackColor="#EEEEEE"  Width="100%" AutoGenerateColumns="False">


 <asp:TemplateField HeaderText="Edit" ItemStyle-CssClass="hs1" HeaderStyle-CssClass="header-center">
 
 <ItemTemplate>

    <asp:LinkButton ID="linkEdit" runat="server"    Text="Edit"  OnClick="linkEdit_Click"/>


  </ItemTemplate>
  </asp:TemplateField>


 Add  label  with Database Column 

 <asp:TemplateField HeaderText="Paper ID" ItemStyle-CssClass="hs1" HeaderStyle-CssClass="header-center">
                    <ItemTemplate>

                      <asp:Label ID="LBLID" runat="server" Text='<%# Eval("ID") %>'></asp:Label>

                     
                    </ItemTemplate>
                </asp:TemplateField>



C#   Code  Link button Event



 protected void paybtn_Click(object sender, EventArgs e)
    {

        GridViewRow clickedRow = ((LinkButton)sender).NamingContainer as GridViewRow;
        Label lblID = (Label)clickedRow.FindControl("LBLID");
        lblJ_ID.Text = lblID.Text;
     
         Session["paperid"] = lblJ_ID.Text;
        Response.Redirect("payment1.aspx");       
     

    }









No comments:

Post a Comment

GRIDVIEW ON ROW DATA BOUND EVENT

 Database Create  Student : roll , name , city , cost  Fix 6 Value  in Database Record  ====================================================...