asp.net c# gridview buttons -
i'm having trouble getting gridview's button column anything. i'm using directoryinfo object details of file. put filename , date created gridview columns. third column button column. have set datakeys(name, creationtime), named button column's commandname "sendcommand". want send filename page. have code rowcommand event:
protected void gvfiles_rowcommand(object sender, system.web.ui.webcontrols.gridviewcommandeventargs e) { if (e.commandname == "sendcommand") { int index = convert.toint32(e.commandargument); string fileid = ((gridview)sender).datakeys[index]["name"].tostring(); response.redirect("irmain.aspx?@filename=" + fileid); } } nothing happens, except postback think. how do this?
<asp:gridview id="gvfiles" runat="server" font-name="verdana" font-names="verdana" width="401px" autogeneratecolumns="false" backcolor="white" bordercolor="black" borderstyle="ridge" borderwidth="2px" datakeynames="name,creationtime" > <columns> <asp:hyperlinkfield accessibleheadertext="file name" datanavigateurlfields="name" datanavigateurlformatstring="~\assets\reports\{0}" datatextfield="name" headertext="file name" > <headerstyle backcolor="#0033cc" forecolor="white" /> </asp:hyperlinkfield> <asp:boundfield accessibleheadertext="date" datafield="creationtime" dataformatstring="{0:d}" headertext="date"> <headerstyle backcolor="blue" forecolor="white" /> </asp:boundfield> <asp:buttonfield buttontype="button" text="do stuff" commandname="sendcommand" headertext="what?!" /> </columns> <alternatingrowstyle backcolor="#6699ff" /> </asp:gridview>
you have add onrowcommand attribute gridview in aspx, otherwise gridview doesn't know method call when execute command on it.
afaik entirely optional attribute , isn't generated via designer have add manually when want use it.
Comments
Post a Comment