c# - dynamically add a link button in gridview template field at run time together a label control -


i have gridview in form. working rowdatabound event grid. have template field inside columns of gridview. label has been taken inside template field. want add link label on rowdatabound event @ runtime, .system.web.ui.webcontrols.linkbutton showing instead of link button. how add link button label text in grid view?

just add linkbutton inside templatefield

<asp:gridview runat="server" id="gridview">         <columns>             <asp:templatefield>                 <itemtemplate>                     <asp:linkbutton runat="server" id="lnktest"></asp:linkbutton>                 </itemtemplate>             </asp:templatefield>         </columns>     </asp:gridview> 

then in rowdatabound event can find , whatever want

void gridview_rowdatabound(object sender, gridviewroweventargs e)     {         if (e.row.rowtype == datacontrolrowtype.datarow)         {             entity entity = e.row.dataitem entity;              linkbutton lnktest = e.row.findcontrol("lnktest") linkbutton;             lnktest.commandargument = entity.id.tostring();             lnktest.text = entity.name;         }     } 

you can subscribe gridview command event , correct commandargument passed when clicking linkbutton. hope helps.


Comments

Popular posts from this blog

How do you change vbulletin's home page to the forums instead of the default (CMS or Activity Stream)? -

c++ - Troubles when compiling phash program -