求助!!在ASP.net中Repeater内嵌DropDownList2的问题 30
我想把一个SQL表中的name,和type搜索出来,用户改DropDownList2的值把它传到数据库里面。。绑定name,type用了Repeater里面有个DropD...
我想把一个SQL表中的name,和type搜索出来,用户改DropDownList2的值把它传到数据库里面。。绑定name,type用了Repeater里面有个DropDownList2,已经绑定好数据了,接下来不知道怎么操作。
sqlstr=“select * from T user”
DataSet ds = SqlHelper.ExecuteDataset(SqlHelper.GetConnection(), CommandType.Text, sqlstr);
this.Repeater1.DataSource = ds.Tables[0];
this.Repeater1.DataBind();
this.Repeater2.DataSource = ds.Tables[0];
this.Repeater2.DataBind();
protected void Repeater2_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
DropDownList dllOperator = (DropDownList)e.Item.FindControl("DropDownList1");
string sqlstr = "select * from T_type ";
DataSet ds = SqlHelper.ExecuteDataset(SqlHelper.GetConnection(), CommandType.Text, sqlstr);
dllOperator.DataTextField = "type";
dllOperator.DataValueField = "id";
dllOperator.DataSource = ds.Tables[0];
dllOperator.DataBind();
dllOperator.Items.Add(new ListItem("-Choose-", ""));
//找到分类Repeater关联的数据项
DataRowView rowv = (DataRowView)e.Item.DataItem;//获取当前项行数据再去访问那一列.注意坐标索引是从0开始
dllOperator.SelectedValue = rowv["id"].ToString();//绑定的数据源字段
}
} 展开
sqlstr=“select * from T user”
DataSet ds = SqlHelper.ExecuteDataset(SqlHelper.GetConnection(), CommandType.Text, sqlstr);
this.Repeater1.DataSource = ds.Tables[0];
this.Repeater1.DataBind();
this.Repeater2.DataSource = ds.Tables[0];
this.Repeater2.DataBind();
protected void Repeater2_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
DropDownList dllOperator = (DropDownList)e.Item.FindControl("DropDownList1");
string sqlstr = "select * from T_type ";
DataSet ds = SqlHelper.ExecuteDataset(SqlHelper.GetConnection(), CommandType.Text, sqlstr);
dllOperator.DataTextField = "type";
dllOperator.DataValueField = "id";
dllOperator.DataSource = ds.Tables[0];
dllOperator.DataBind();
dllOperator.Items.Add(new ListItem("-Choose-", ""));
//找到分类Repeater关联的数据项
DataRowView rowv = (DataRowView)e.Item.DataItem;//获取当前项行数据再去访问那一列.注意坐标索引是从0开始
dllOperator.SelectedValue = rowv["id"].ToString();//绑定的数据源字段
}
} 展开
2015-02-14
展开全部
用repeater的ItemDataBound事件
------------------------------
aspx
<asp:Repeater ID="repeater" runat="server" OnItemDataBound="repeater_ItemDataBound">
<ItemTemplate>
<asp:Repeater ID="child" runat="server">
<ItemTemplate>
.....
</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:Repeater>
---------------------------
aspx.cs
protected void repeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
IList<Order> orderList=(IList<Order>)repeater.DataSource;
Repeater rep = (Repeater)e.Item.FindControl("child");
rep.DataSource=
orderList.ProductList;
rep.DataBind();
}
}
------------------------------
aspx
<asp:Repeater ID="repeater" runat="server" OnItemDataBound="repeater_ItemDataBound">
<ItemTemplate>
<asp:Repeater ID="child" runat="server">
<ItemTemplate>
.....
</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:Repeater>
---------------------------
aspx.cs
protected void repeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
IList<Order> orderList=(IList<Order>)repeater.DataSource;
Repeater rep = (Repeater)e.Item.FindControl("child");
rep.DataSource=
orderList.ProductList;
rep.DataBind();
}
}
追问
这是绑定的吧,我绑定好了,想传回数据库怎么做,在线等
Storm代理
2023-08-29 广告
2023-08-29 广告
"StormProxies是全球大数据IP资源服务商,其住宅代理网络由真实的家庭住宅IP组成,可为企业或个人提供满足各种场景的代理产品。点击免费测试(注册即送1G流量)StormProxies有哪些优势?1、IP+端口提取形式,不限带宽,I...
点击进入详情页
本回答由Storm代理提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询