Datalist Problem

9 views
Skip to first unread message

Arsalan

unread,
Mar 19, 2005, 2:48:17 PM3/19/05
to
Well, suppose i have couple of controls in datalist and one of them is link
button control

how do i invoke link button controls click method in the datalist ???

Suppose link button control will send info back to server and redirect to
another page, how do i do it in datalist ?

I have following code in item templatae
<asp:LinkButton id="Linkbutton1" OnClick="OnClickMethod"
runat="server">Download Chapter</asp:LinkButton>


I want to be able to pass arguement to OnClickMethod [the arguement is
employee_id which comes from the table]

Something like when link button is clicked, it'll redirect to another page
containing employee details.

Brock Allen

unread,
Mar 19, 2005, 4:45:55 PM3/19/05
to
In your ItemTemplate make the LinkButton have a CommandName="DoSomething".
On your Datalist specify the primary key for the rows via the DataKeyField="employee_id"
attribute. Then handle the DataList's ItemCommand event to do something like
this:

protected void _dataList_ItemCommand(object source, DataListCommandEventArgs
e)
{
if (e.CommandName == "DoSomething")
{
int employee_id = (int)_dataList.DataKeys[e.Item.ItemIndex];
// now do something with
}
}

But if your going to do all of this simply for a redirect, then it's much
simpler to just emit a hyperlink to the browser in the first place. This
also can be accomplished in your ItemTempate:

<asp:HyperLink runat="server" Text="Something"
NavigateUrl='OtherPage.aspx?EmpID=<%# DataBinder.Eval(Container.DataItem,
"employee_id") %>'></asp:HyperLink>

-Brock
DevelopMentor
http://staff.develop.com/ballen

Arsalan

unread,
Mar 20, 2005, 2:20:09 AM3/20/05
to
Thanks
"Brock Allen" <bal...@develop.com.i_hate_spam_too> wrote in message
news:78003632468...@msnews.microsoft.com...
Reply all
Reply to author
Forward
0 new messages