Welcome to WebmasterWorld Guest from 54.226.62.251

Forum Moderators: ocean10000

Message Too Old, No Replies

Buttons in DataLists

     

mtyrpa

8:22 pm on Apr 12, 2006 (gmt 0)



Hi All,

I'm want to be able to use a button in a datalist, but I want it to do something beyond the onEditCommand, OnCancelCommand, etc... that is built into to the DataList. Is this possible?

For example:

<asp:DataList ID="dlSystemsImpacted" runat="server" CellPadding="0" ForeColor="#333333" DataSource='<%# DataBinder.Eval(Container, "DataItem.SysImpactRelation") %>'>
<FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<SelectedItemStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
<ItemTemplate>
<asp:Button ID="btnApproval" runat="server" Text="Approve" />
</ItemTemplate>
<ItemStyle BackColor="White" />
<HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
</asp:DataList>

In the code behind page, I cannot get to that button. How do I create a method that will fire when that button is pressed?

I am doing this is VS2005, ASP.Net 2.0, c#

Thanks,
Marek

sharbel

11:30 pm on Apr 12, 2006 (gmt 0)

10+ Year Member



You can actually just use the OnClick attribute of the button, and the method will fire. For example:

<asp:DataList ID="dlSystemsImpacted" runat="server" CellPadding="0" ForeColor="#333333" DataSource='<%# DataBinder.Eval(Container, "DataItem.SysImpactRelation") %>'>
<FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<SelectedItemStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
<ItemTemplate>
<asp:Button ID="btnApproval" runat="server" Text="Approve" OnClick="MyMethod" />
</ItemTemplate>
<ItemStyle BackColor="White" />
<HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
</asp:DataList>


protected void MyMethod(object sender, EventArgs e)
{
//do your stuff
}

mtyrpa

3:57 pm on Apr 17, 2006 (gmt 0)



Thanks a lot, that did the trick!

Marek

 

Featured Threads

Hot Threads This Week

Hot Threads This Month