Sunday, July 19, 2009

Calling a function when button is clicked in datagrid

So you have a datagrid that's automatically populated by your data, including dynamically generated links.

For example, you allow people to search for books, and you want them to be able to click on a link to the books that are returned in the search...well you need to dynamically generate the links based on the books ID. etc...

Well sometimes you also need to be able to call a function to do some additional processing when the list is generated. Here's the code necessary to do this:

<asp:TemplateField HeaderText="Video Links" >
<asp:LinkButton OnCommand="lbEdit_Click" ID="lbEdit" CommandName="Edit" CommandArgument='<%# Eval("VideoID").ToString() %>)' runat="server" Text="Edit Video">

In the C# behind code file:
protected void lbEdit_Click(object sender, CommandEventArgs e)
//Pass the contextual info to the next function

No comments:

Post a Comment

There was an error in this gadget