c# - Disable/ Hide a control inside a specific row of GridView -
i have below code create gridview in asp.net , inside gridview have delete button. below code works fine , shows delete in rows. want hide/ disable delete button in first row. can suggest code part?
<asp:gridview id="gridview1" runat="server" showfooter="true" autogeneratecolumns="false"> <columns> <asp:boundfield datafield="rownumber" headertext="row number" /> <asp:templatefield headertext="cat"> <itemtemplate> <asp:textbox id="textboxcat" runat="server" enabled="false"></asp:textbox> </itemtemplate> </asp:templatefield> <asp:templatefield headertext="delete" > <itemtemplate> <asp:linkbutton id="deleteitemsgridrowbutton" runat="server">delete</asp:linkbutton> </itemtemplate> </asp:templatefield> </columns> </asp:gridview>
you can use gridview.rowdatabound event event.
then find linkbutton using findcontrol method.
public class animal { public int rownumber { get; set; } public string name { get; set; } } protected void page_load(object sender, eventargs e) { if (!ispostback) { gridview1.datasource = new list<animal> { new animal {rownumber = 1, name = "one"}, new animal {rownumber = 2, name = "two"}, new animal {rownumber = 3, name = "three"}, new animal {rownumber = 4, name = "four"}, }; gridview1.databind(); } } private int _counter; protected void gridview1_rowdatabound(object sender, gridviewroweventargs e) { if (e.row.rowtype == datacontrolrowtype.datarow) { if (_counter == 0) { var linkbutton = e.row.findcontrol("deleteitemsgridrowbutton") linkbutton; linkbutton.visible = false; _counter++; } } }
Comments
Post a Comment