Hi all,
I'm trying to find the best way to call a method (defined in CodeBehind) from a linkbutton in a DataList.
An example to clear things up:
DATALIST:
ID NAME
----------------------
123 Mercedes
124 Opel
125 Chevrolet
The linkbutton is for each row the name (Linkbutton1: "Mercedes" ...)
When you click on the linkbutton Mercedes I want to do some work in my code with "123" & "Mercedes" as parameters.
this is the sourcecode:(does not work)
Code:
<asp:DataList ID="_dlCompanyList" runat="server" style="z-index: 106; left: 1px; position: absolute; top: 3px" BackColor="White" BorderColor="#E7E7FF" BorderStyle="None" BorderWidth="1px" CellPadding="3" GridLines="Horizontal" ShowFooter="False" ShowHeader="False" Width="95%">
<ItemTemplate>
<asp:Label ID="_lBullet" runat="server" Text="â¢" Width="5px"></asp:Label>
<asp:LinkButton ID="LinkButton1" runat="server" Width="100px" Text='<%# Eval("Name") %>' OnClick="CompanyClick( Eval("Id") )"></asp:LinkButton>
<asp:Label ID="_lCompanyVersion" runat="server" Width="20px" Text='<%# Eval("Version") %>'></asp:Label>
</ItemTemplate>
<FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
<SelectedItemStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" />
<AlternatingItemStyle BackColor="#F7F7F7" />
<ItemStyle BackColor="#E7E7FF" Font-Size="Small" ForeColor="#4A3C8C" />
<HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" />
</asp:DataList>
And this the method in the codebehind:
Code:
public void CompanyClick(Object sender, EventArgs e, string companyId)
{
//do some work with companyId
}
I read you can do something with OnCommand and CommandArgs in the Source Code but I'm realy looking for the best solution here.
thx in advance for any help.
grtz