开发者

How to add a button to gridview controller

I have record from sql database printing into gridview. I want to make another column that will add a button that I can link to开发者_如何学JAVA in the Code Behind. When I use asp:ButtonField I cant find a way to link it to a function... Also how can i associate it with the id that is being printed? So if I wanted the button to delete the record, how can I make it so it knows its id number 10 so it will pass that id to the Code Behind so I can delete the appropriate record.


you must need this, I think

 <asp:TemplateField>
      <ItemTemplate>
                    <asp:Button ID="btnDelete" CommandArgument='<%# Eval("Printedid") %>' CommandName="Delete"  />
      </ItemTemplate>
  </asp:TemplateField>

and then you can get in code behind of that particular id

protected void grd_RowCommand(object sender, GridViewCommandEventArgs e)
{
    if (e.CommandName == "Delete")
    {
       e.CommandArgument // will return the Rrinted id 
    }        
}


The button field will call the RowCommand event passing in the command name and command argument that you specify in the field.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜