高分求解:DataList嵌套问题,获取内层datalist列表ID号的方法
问题描述:
我在后台做栏目管理的设置,就做二级栏目就可以了,数据库中一个表实现的。使用DATALIST嵌套,外层和内层列表实现删除一级根栏目和二级子栏目的功能,一级栏目可以实现,ID号很好获取,但是内层的怎么都获取不到ID值所以无法删除。
求救:很急,希望给出解决方法最好有代码实例。谢谢。解决后立刻结贴。我使用的是1.1框架,C#!!
------解决方案--------------------给你一个例子,实现了内层的删除,外层的你就自己解决一下吧,用的是pubs数据库
//aspx
<%@ Page language= "c# " Codebehind= "DataListDemo.aspx.cs " AutoEventWireup= "false " Inherits= "WebForm1 " %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN " >
<HTML>
<HEAD>
<title> WebForm1 </title>
<meta content= "Microsoft Visual Studio .NET 7.1 " name= "GENERATOR ">
<meta content= "C# " name= "CODE_LANGUAGE ">
<meta content= "JavaScript " name= "vs_defaultClientScript ">
<meta content= "http://schemas.microsoft.com/intellisense/ie5 " name= "vs_targetSchema ">
<script language= "javascript ">
function DeleteTitle(au_id, title_id)
{
if (confirm( '真的删除? '))
{
document.getElementById( 'auid ').value = au_id;
document.getElementById( 'titleid ').value = title_id;
__doPostBack( 'DeleteTitle ', ' ');
}
}
</script>
</HEAD>
<body>
<form id= "Form1 " method= "post " runat= "server ">
<input type= "hidden " ID= "titleid " runat= "server " NAME= "title_id "> <input type= "hidden " ID= "auid " runat= "server " NAME= "au_id ">
<asp:LinkButton ID= "DeleteTitle " runat= "server " OnClick= "DeleteTitle_Click " Visible= "False " />
<asp:datalist id= "DataList1 " runat= "server " DataKeyField= "au_id " BorderColor= "#CC9966 " BorderStyle= "None "
BackColor= "White " CellPadding= "4 " GridLines= "Both " BorderWidth= "1px ">
<SelectedItemStyle Font-Bold= "True " ForeColor= "#663399 " BackColor= "#FFCC66 "> </SelectedItemStyle>
<FooterStyle ForeColor= "#330099 " BackColor= "#FFFFCC "> </FooterStyle>
<ItemStyle ForeColor= "#330099 " BackColor= "White "> </ItemStyle>
<ItemTemplate>
au_id:
<asp:Label id=Label1 runat= "server " Text= ' <%# DataBinder.Eval(Container.DataItem, "au_id ")%> '>
</asp:Label> <BR>
au_lname:
<asp:Label id=Label2 runat= "server " Text= ' <%# DataBinder.Eval(Container.DataItem, "au_lname ")%> '>
</asp:Label> <BR>
<asp:LinkButton id= "lbtnDelete " runat= "server " CommandName= "delete "> 删除 </asp:LinkButton>
<asp:DataList id=DataList2 runat= "server " DataKeyField= "Title_id " DataSource= ' <%# GetTitleID(DataBinder.Eval(Container.DataItem, "au_id ").ToString()) %> ' BorderColor= "#CC9966 " BorderStyle= "None " BackColor= "White " CellPadding= "4 " GridLines= "Both " BorderWidth= "1px ">
<SelectedItemStyle Font-Bold= "Tru