homepage Welcome to WebmasterWorld Guest from 54.211.181.45
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Microsoft / Microsoft IIS Web Server and ASP.NET
Forum Library, Charter, Moderators: ocean10000

Microsoft IIS Web Server and ASP.NET Forum

    
Buttons in DataLists
mtyrpa

10+ Year Member



 
Msg#: 3350 posted 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

10+ Year Member



 
Msg#: 3350 posted 11:30 pm on Apr 12, 2006 (gmt 0)

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

10+ Year Member



 
Msg#: 3350 posted 3:57 pm on Apr 17, 2006 (gmt 0)

Thanks a lot, that did the trick!

Marek

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Microsoft / Microsoft IIS Web Server and ASP.NET
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved