DataList

19 views
Skip to first unread message

Eduardo Rosa

unread,
Mar 16, 2005, 1:31:50 PM3/16/05
to
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


Brock Allen

unread,
Mar 16, 2005, 2:06:43 PM3/16/05
to
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

-Brock
DevelopMentor
http://staff.develop.com/ballen

Eduardo Rosa

unread,
Mar 30, 2005, 5:04:35 PM3/30/05
to
Thanks a lot!!!
It gimme some headache and now the software's working!


"Brock Allen" <bal...@develop.com.i_hate_spam_too> escreveu na mensagem
news:29481632465...@msnews.microsoft.com...

Reply all
Reply to author
Forward
0 new messages