datalist嵌套子datalist获取不到ID的值
前台:<asp:DataListID="rptParent"runat="server"OnItemDataBound="rptParent_ItemDataBound"...
前台:
<asp:DataList ID="rptParent" runat="server" OnItemDataBound="rptParent_ItemDataBound" OnItemCommand="rptParent_ItemCommand">
<ItemTemplate>
....
子datalist
<asp:DataList ID="rptChild" runat="server">
<ItemTemplate>
<tr>
<td width="53"></td>
<td width="600"><img src="images/Sitem.gif" alt="" /> <%#Eval("SmItemTitle")%></td>
<td align="left"><a href ='#'onclick="toggle('c<%#Eval("SmItemID")%>','d<%#Eval("SmItemID")%>')" id="d<%#Eval("SmItemID")%>" style="color:#000000"> 修改</a> | <asp:LinkButton ID="Delete" CommandArgument='<%#Eval("SmItemID")%>' OnClick="LinkButton1_Click" runat="server" ForeColor="#000000" CommandName="Delete" OnClientClick="return confirm('确认要删除此行信息吗?')">删除</asp:LinkButton></td>
</tr>
<tr style="display:none" id="c<%#Eval("SmItemID")%>">
<td width="30" style=" border-bottom:1px solid #e1eeff" ></td>
<td colspan="3" style=" border-bottom:1px solid #e1eeff" align="left" height="50">
子栏目名称:<asp:TextBox ID="TxteSitem" runat="server" Width="130px"></asp:TextBox>
子栏目链接:<asp:TextBox ID="TxteSLink" runat="server" Width="150px"></asp:TextBox>
<asp:TextBox ID="hidden2" runat="server" Text='<%#Eval("SmItemID")%>' Visible="False" />
<asp:Button ID="Button3" runat="server" Text="修改" />
</td>
</tr>
</ItemTemplate>
</asp:DataList>
</ItemTemplate>
</asp:DataList>
后台:
protected void rptParent_ItemDataBound(object sender, DataListItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
DataList child2 = (DataList)e.Item.FindControl("rptChild");
TextBox a = (TextBox)e.Item.FindControl("TxteSitem");
TextBox b = (TextBox)e.Item.FindControl("TxteSLink");
TextBox c = (TextBox)e.Item.FindControl("hidden2");
int txtsid = int.Parse(c.Text);
Maticsoft.BLL.SYS_SItem typebsbll = new Maticsoft.BLL.SYS_SItem();
Maticsoft.Model.SYS_SItem typesmodel = typebsbll.GetModel(txtsid);
a.Text = typesmodel.SmItemTitle;
b.Text = typesmodel.SmItemLink;
}
}
完全获取不到a,b,c的值,方法好像没错,但显示:未将对象引用设置到对象的实例,原因是a,b,c的值获取不到 展开
<asp:DataList ID="rptParent" runat="server" OnItemDataBound="rptParent_ItemDataBound" OnItemCommand="rptParent_ItemCommand">
<ItemTemplate>
....
子datalist
<asp:DataList ID="rptChild" runat="server">
<ItemTemplate>
<tr>
<td width="53"></td>
<td width="600"><img src="images/Sitem.gif" alt="" /> <%#Eval("SmItemTitle")%></td>
<td align="left"><a href ='#'onclick="toggle('c<%#Eval("SmItemID")%>','d<%#Eval("SmItemID")%>')" id="d<%#Eval("SmItemID")%>" style="color:#000000"> 修改</a> | <asp:LinkButton ID="Delete" CommandArgument='<%#Eval("SmItemID")%>' OnClick="LinkButton1_Click" runat="server" ForeColor="#000000" CommandName="Delete" OnClientClick="return confirm('确认要删除此行信息吗?')">删除</asp:LinkButton></td>
</tr>
<tr style="display:none" id="c<%#Eval("SmItemID")%>">
<td width="30" style=" border-bottom:1px solid #e1eeff" ></td>
<td colspan="3" style=" border-bottom:1px solid #e1eeff" align="left" height="50">
子栏目名称:<asp:TextBox ID="TxteSitem" runat="server" Width="130px"></asp:TextBox>
子栏目链接:<asp:TextBox ID="TxteSLink" runat="server" Width="150px"></asp:TextBox>
<asp:TextBox ID="hidden2" runat="server" Text='<%#Eval("SmItemID")%>' Visible="False" />
<asp:Button ID="Button3" runat="server" Text="修改" />
</td>
</tr>
</ItemTemplate>
</asp:DataList>
</ItemTemplate>
</asp:DataList>
后台:
protected void rptParent_ItemDataBound(object sender, DataListItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
DataList child2 = (DataList)e.Item.FindControl("rptChild");
TextBox a = (TextBox)e.Item.FindControl("TxteSitem");
TextBox b = (TextBox)e.Item.FindControl("TxteSLink");
TextBox c = (TextBox)e.Item.FindControl("hidden2");
int txtsid = int.Parse(c.Text);
Maticsoft.BLL.SYS_SItem typebsbll = new Maticsoft.BLL.SYS_SItem();
Maticsoft.Model.SYS_SItem typesmodel = typebsbll.GetModel(txtsid);
a.Text = typesmodel.SmItemTitle;
b.Text = typesmodel.SmItemLink;
}
}
完全获取不到a,b,c的值,方法好像没错,但显示:未将对象引用设置到对象的实例,原因是a,b,c的值获取不到 展开
3个回答
展开全部
我记得之前也遇到过。。
e.Item.ItemType调试下,取到的是什么值啊?
e.Item.ItemType调试下,取到的是什么值啊?
追问
就 因为a,b,c都取不到值,我想是因为这个子datalist的原因,但我现在用的这个方法就是获取子datalist下ID的方法吧??
追答
按我的理解,你绑定的事件源还在子datalist里,你取到的值只能在子嵌套里。你如果foreach一下看有几个item count值是多少 就知道你用的是子datalist 还是父datalist的。我也在摸索中
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2012-09-19
展开全部
你测试下是否执行了rptParent_ItemDataBound
更多追问追答
追问
执行了,rptParent_ItemDataBound 里面还有其他代码的,都执行了,就我发出来那段没执行
追答
TextBox a = (TextBox)e.Item.FindControl("TxteSitem");
TextBox b = (TextBox)e.Item.FindControl("TxteSLink");
TextBox c = (TextBox)e.Item.FindControl("hidden2");
不在rptParent_ItemDataBound里面,应该在rptChild_ItemDataBound里面绑定吧
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询