Datalist Problem

A

Arsalan

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

Brock Allen

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
 
A

Arsalan

Thanks
Brock Allen said:
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


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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top