Saturday, 15 May 2010

c# - Changing the text of a linkbutton of a gridview dynamically on the basis of a column value -



c# - Changing the text of a linkbutton of a gridview dynamically on the basis of a column value -

i php background. have next code gridview getting populated database. want alter text of link button based on value of status column in grid. example, if value of status column 'pending' link button should show text edit details instead of view details. how do this?

<asp:gridview id="empres1" runat="server" allowpaging="true" autogeneratecolumns="false" onrowcommand="empres1_rowcommand" onrowediting="empres1_rowediting" onselectedindexchanged="empres1_selectedindexchanged1"> <asp:boundfield datafield="status" headertext="status" /> <asp:boundfield datafield="comments" headertext="comments" /> <asp:templatefield headertext="" sortexpression=""> <itemtemplate> <asp:linkbutton id="linkbuttonedit" runat="server" commandname="showpopup" commandargument='<%#eval("employeeid") %>'>view details </asp:linkbutton> -------------------^ </itemtemplate> </asp:templatefield> </columns> </asp:gridview>

you can utilize server side event of grid view:

gridview.rowcreated event

in event can acces controls created within row, , modify them, this:

if(e.row.rowtype == datacontrolrowtype.datarow) // (1) { // modify row here }

(1) skips headers , footers, code runs "regular" rows

in // modify row here can acces controls within row, , modify them.

you can alternatively utilize gridview.rowdatabound event, has info of info passed row (in similar fashion previous sample).

in both cases have row available, , can access of properties. you'll utilize these properties:

cells: cells (columns) of row controls: controls within row dataitem: lets acces info bound route (you can utilize debugger see how lloks create necessary casting)

the process @ info in dataitem, , command (or cell) need modify. (i insist on using breakpoint on debugger browse values of properties... bit cumbersome, specially info item).

c# asp.net

No comments:

Post a Comment