0

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 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.

2 Answers 2

2

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 
    }        
}
Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.