I hope You mean CommandName of a Button in the child DataList.. am I right?
First You have find out the Child DataList using FindControl method of the Parent DataList Then you have to find the Button using the FindControl method of the newly found out Child DtaList. Only then you can get the CommandName of the button.B
Kindly mark this post as "Answer", if it helped you.
Protected Sub DataList1_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataListCommandEventArgs) Handles DataList1.ItemCommand
Dim myChildDataList As DataList = e.Item.FindControl("DataList2")
If e.CommandName = "CmdSehirGuncelle" Then 'Some codes goes here.
ElseIf e.CommandName = "CmdMerkezGuncelle" Then 'As you see this command name belogns to child DataList2 button
'But it does not work.
'Some codes goes here.
End If
End Sub
Protected Sub DataList1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs) Handles DataList1.ItemDataBound
Dim mySehirID As Integer = DataList1.DataKeys.Item(e.Item.ItemIndex)
Dim myMerkezDataList As DataList = e.Item.FindControl("DataList2")
Sabitler.Public_DataListBagla(MyConn2, myMerkezDataList, "SELECT * FROM TblSehirlerMerkezler WHERE UstSehirID = " & mySehirID & " ORDER BY Merkez ASC")
End Sub
I hope You mean CommandName of a Button in the child DataList.. am I right?
First You have find out the Child DataList using FindControl method of the Parent DataList Then you have to find the Button using the FindControl method of the newly found out Child DtaList. Only then you can get the CommandName of the button.B
protected void DataList2_ItemCommand(object source, DataListCommandEventArgs e)
{
if (e.CommandName == "btn in ineer datalist commandName"){// do what you want}
ardilo
Member
33 Points
101 Posts
CommandName of a datalist inside another datalist?
Apr 08, 2012 06:40 AM|LINK
Dear friends,
I put a datalist inside another datalist. I works fine... But I couldn't call the CommandName of the inner datalist?
I look forward to hear from you...
Regards,
reza141414
Participant
1571 Points
497 Posts
Re: CommandName of a datalist inside another datalist?
Apr 08, 2012 06:53 AM|LINK
dont forget to mark as answerd...
basheerkal
Star
10672 Points
2426 Posts
Re: CommandName of a datalist inside another datalist?
Apr 08, 2012 09:35 AM|LINK
I hope You mean CommandName of a Button in the child DataList.. am I right?
First You have find out the Child DataList using FindControl method of the Parent DataList Then you have to find the Button using the FindControl method of the newly found out Child DtaList. Only then you can get the CommandName of the button.B
(Talk less..Work more)
ardilo
Member
33 Points
101 Posts
Re: CommandName of a datalist inside another datalist?
Apr 08, 2012 11:09 AM|LINK
Hi,
Markup:
<asp:DataList ID="DataList1" runat="server" DataKeyField="SehirID"
Width="370px">
<ItemTemplate>
<table style="width: 100%;" bgcolor="#CCCCCC">
<tr>
<td class="style1">
<asp:Label ID="LblSehir" runat="server" Text='<%# Eval("Sehir") %>'></asp:Label>
</td>
<td class="style2">
<asp:LinkButton ID="LinkButton1" runat="server" CommandName="CmdSehirGuncelle">Güncelle</asp:LinkButton>
</td>
<td>
<asp:LinkButton ID="LinkButton2" runat="server" CommandName="CmdSehirSil">Sil</asp:LinkButton>
</td>
</tr>
</table>
<asp:DataList ID="DataList2" runat="server" Width="292px"
DataKeyField="MerkezID" style="float:right;">
<ItemTemplate>
<table style="width:100%;">
<tr>
<td class="style5">
<asp:Label ID="LblMerkez" runat="server" Text='<%# Eval("Merkez") %>'></asp:Label>
</td>
<td class="style4">
<asp:LinkButton ID="LinkButton3" runat="server" CommandName="CmdMerkezGuncelle">Güncelle</asp:LinkButton>
</td>
<td>
<asp:LinkButton ID="LinkButton4" runat="server" CommandName="CmdMerkezSil">Sil</asp:LinkButton>
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
</ItemTemplate>
</asp:DataList>
Codebehind:
Protected Sub DataList1_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataListCommandEventArgs) Handles DataList1.ItemCommand
Dim myChildDataList As DataList = e.Item.FindControl("DataList2")
If e.CommandName = "CmdSehirGuncelle" Then
'Some codes goes here.
ElseIf e.CommandName = "CmdMerkezGuncelle" Then
'As you see this command name belogns to child DataList2 button
'But it does not work.
'Some codes goes here.
End If
End Sub
Protected Sub DataList1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs) Handles DataList1.ItemDataBound
Dim mySehirID As Integer = DataList1.DataKeys.Item(e.Item.ItemIndex)
Dim myMerkezDataList As DataList = e.Item.FindControl("DataList2")
Sabitler.Public_DataListBagla(MyConn2, myMerkezDataList, "SELECT * FROM TblSehirlerMerkezler WHERE UstSehirID = " & mySehirID & " ORDER BY Merkez ASC")
End Sub
ardilo
Member
33 Points
101 Posts
Re: CommandName of a datalist inside another datalist?
Apr 08, 2012 11:11 AM|LINK
Thanks for your response. I'll try...
reza141414
Participant
1571 Points
497 Posts
Re: CommandName of a datalist inside another datalist?
Apr 08, 2012 11:43 AM|LINK
hi..
i think it is so easy...see:
protected void DataList2_ItemCommand(object source, DataListCommandEventArgs e) { if (e.CommandName == "btn in ineer datalist commandName"){// do what you want}dont forget to mark as answerd...
ardilo
Member
33 Points
101 Posts
Re: CommandName of a datalist inside another datalist?
Apr 08, 2012 12:21 PM|LINK
Hi,
I tested it. Since it is childcontrol, it says "DataList2 is not declared".
:(
reza141414
Participant
1571 Points
497 Posts
Re: CommandName of a datalist inside another datalist?
Apr 08, 2012 12:26 PM|LINK
hi
i tested it and work fine...
<asp:DataList ID="DataList1" runat="server" DataKeyField="Reservation_num" DataSourceID="SqlDataSource1"> <ItemTemplate> Reservation_num: <asp:Label ID="Reservation_numLabel" runat="server" Text='<%# Eval("Reservation_num") %>' /> <br /> Member_id: <asp:Label ID="Member_idLabel" runat="server" Text='<%# Eval("Member_id") %>' /> <br /> <asp:DataList ID="DataList2" runat="server" DataKeyField="Reservation_num" DataSourceID="SqlDataSource2" onitemcommand="DataList2_ItemCommand" onselectedindexchanged="DataList2_SelectedIndexChanged"> <ItemTemplate> <asp:Button ID="Button1" runat="server" CommandArgument='<%# Eval("Member_id") %>' CommandName="test" Text="Button" /> <br /> </ItemTemplate> </asp:DataList> </ItemTemplate> </asp:DataList>dont forget to mark as answerd...
ardilo
Member
33 Points
101 Posts
Re: CommandName of a datalist inside another datalist?
Apr 08, 2012 01:00 PM|LINK
OK...
I missed onitemcommand="DataList2_ItemCommand" string..
Thanks for your support...