DataList

E

Eduardo Rosa

Hello people,

I'm using DataList to show some info from db (sqlserver), my question is
about how make a button that call a function to do something using info from
a line of the DataList.

I explain:
The code below will write a table with the values (from db) in their cells,
what I want is a button (asp:Button) with onclick event using (some way) the
cell datalist info.

Code:
<asp:DataList id="sectionList" runat="server" >
<HeaderStyle BackColor="#aaaadd"/>

<ItemStyle CssClass="admin-main-sections-datagrid-item" />
<AlternatingItemStyle CssClass="admin-main-sections-datagrid-item2" />

<HeaderTemplate>
<table >
<td class="admin-main-sections-datagrid-c1">Departamento</td>
<td class="admin-main-sections-datagrid-c3">Categorias</td>
<td class="admin-main-sections-datagrid-c4">Editar</td>
<td class="admin-main-sections-datagrid-c5">Remover</td>
</table>
</HeaderTemplate>

<ItemTemplate>
<table >
<td class="admin-main-sections-datagrid-c1"><%#
DataBinder.Eval(Container.DataItem, "Departamento") %> </td>
<td class="admin-main-sections-datagrid-c3"><%#
DataBinder.Eval(Container.DataItem, "Categorias") %> </td>
<td class="admin-main-sections-datagrid-c4"><%#
DataBinder.Eval(Container.DataItem, "Codigo") %> </td>
<td class="admin-main-sections-datagrid-c5">
<asp:Button ID="btnRemove" runat="server" Text="remover"
onclick="btnRemove_Click" />
<!-- that button need to send
DataBinder.Eval(Container.DataItem, "Remove") to onclicke handler //-->
</td>
</table>
</ItemTemplate>

</asp:DataList>

thanks a lot developers
 
B

Brock Allen

Add a CommandName to your <asp:Button CommandName="Something"> then handle
the DataList's ItemCommand event. In the event check the DataListCommandEventArgs
param that's passed. If DataListCommandEventArgs.CommandName == "Something"
then you can access the row in the DataList via DataListCommandEventArgs.Item
and use FindControl to access the rest of the controls in that row. HTH
 

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

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top