注册 登录
编程论坛 ASP.NET技术论坛

登录后DropDownList绑定

yunj1105 发布于 2007-05-24 17:41, 796 次点击
我在DataGrid的中用了一个模版列添加了一个DropDownList然后在ItemDataBound里绑定
问下怎么才能在一登录这个页面时,就绑定啊?
我在登录后,DropDownList没有绑定
6 回复
#2
bygg2007-05-24 18:03

你统一绑定就行了.
先把那个DropDownList通过FindControls找出来.再给它赋个数据就行了.

#3
川流不息2007-05-25 12:22
我想,你是不是在Page_Load事件中,沒有給datagrid控件去綁定值?或者,你給datagrid控件綁定時根本就沒值。
#4
凌枫影2007-05-25 15:32
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
Dim ddl As DropDownList = CType(e.Row.FindControl("DropDownList2"), DropDownList)
ddl.Items.Add(New ListItem("1", "1"))
ddl.Items.Add(New ListItem("2", "2"))
ddl.Items.Add(New ListItem("3", "3"))
End If
End Sub


寫在GridView1_RowDataBound這個事件中
#5
yunj11052007-05-25 17:00
我在Page_Load事件中給datagrid控件綁定值了,
那datagrid控件綁定時有值啊,而且出了DropDownList其他的都绑上数据了啊

#6
yunj11052007-05-27 15:06

大家来看啊 还没解决呢 我的代码如下:
<asp:DataGrid ID="DataGrid1" runat="server" AllowPaging="True" AutoGenerateColumns="false" BackColor="white" CellSpacing="1" GridLines="Vertical" Width="784px" Height="542px">
<SelectedItemStyle BackColor="White" Font-Bold="True" />
<HeaderStyle BackColor="#00CC66" Font-Bold="True" ForeColor="White" />
<ItemStyle BackColor="White" />
<AlternatingItemStyle BackColor="#CCFFCC" />
<Columns>
<asp:BoundColumn DataField=Cou_ID HeaderText=课程ID></asp:BoundColumn>
<asp:BoundColumn DataField=Cou_name HeaderText=课程名></asp:BoundColumn>
<asp:TemplateColumn>
<ItemTemplate>
<asp:RadioButtonList runat=server Width=60px ID=rad DataValueField=Cou_flag>
<asp:ListItem Text="必选" Value=0></asp:ListItem>
<asp:ListItem Text="选修" Value=1></asp:ListItem>
</asp:RadioButtonList>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="教师一">
<ItemTemplate>
<asp:DropDownList runat=server ID=drptea DataTextField=user_name DataValueField=user_ID Width=50px></asp:DropDownList>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="教师二">
<ItemTemplate>
<asp:DropDownList runat=server ID=drptea1 DataTextField=user_name DataValueField=user_ID Width=50px></asp:DropDownList>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="教师三">
<ItemTemplate>
<asp:DropDownList runat=server ID=drptea2 DataTextField=user_name DataValueField=user_ID Width=50px></asp:DropDownList>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="起始周">
<ItemTemplate>
<asp:DropDownList runat=server ID=drp DataTextField=Cou_week DataValueField=week_date Width=50px></asp:DropDownList>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="结束周">
<ItemTemplate>
<asp:DropDownList runat=server ID=drp1 DataTextField=Cou_week DataValueField=week_date Width=50px></asp:DropDownList>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="起始星期">
<ItemTemplate>
<asp:DropDownList runat=server ID=drp2>
<asp:ListItem Text=星期一 Value=1></asp:ListItem>
<asp:ListItem Text=星期二 Value=2></asp:ListItem>
<asp:ListItem Text=星期三 Value=3></asp:ListItem>
<asp:ListItem Text=星期四 Value=4></asp:ListItem>
<asp:ListItem Text=星期五 Value=5></asp:ListItem>
<asp:ListItem Text=星期六 Value=6></asp:ListItem>
<asp:ListItem Text=星期日 Value=7></asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="结束星期">
<ItemTemplate>
<asp:DropDownList runat=server ID=drp3>
<asp:ListItem Text=星期一 Value=1></asp:ListItem>
<asp:ListItem Text=星期二 Value=2></asp:ListItem>
<asp:ListItem Text=星期三 Value=3></asp:ListItem>
<asp:ListItem Text=星期四 Value=4></asp:ListItem>
<asp:ListItem Text=星期五 Value=5></asp:ListItem>
<asp:ListItem Text=星期六 Value=6></asp:ListItem>
<asp:ListItem Text=星期日 Value=7></asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText=上课时间>
<ItemTemplate>
<asp:DropDownList runat=server ID=drp4>
<asp:ListItem Text=1--2></asp:ListItem>
<asp:ListItem Text=3--4></asp:ListItem>
<asp:ListItem Text=5--7></asp:ListItem>
<asp:ListItem Text=8--11></asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText=上课人数>
<ItemTemplate>
<asp:TextBox runat=server ID=txt Width=20px></asp:TextBox>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
<PagerStyle BackColor="#00CC66" ForeColor="Black" HorizontalAlign="Justify" Mode="NumericPages" />
</asp:DataGrid>

private Comm1 co_cla = new Comm1();
protected void Page_Load(object sender, EventArgs e)
{
string str_cla = "select * from lab_course";
co_cla.dg_Bind(str_cla, DataGrid1);
}
protected void datagrid_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
foreach (DataGridItem Item in DataGrid1.Items)
{
string str_date = "select * from lab_date";
DropDownList dropdownlist = (DropDownList)e.Item.Cells[6].FindControl("drp");
co_cla.dr_Bind(str_date, dropdownlist);
dropdownlist.DataBind();
DropDownList dropdownlist1 = (DropDownList)e.Item.Cells[7].FindControl("drp1");
co_cla.dr_Bind(str_date, dropdownlist1);
dropdownlist1.DataBind();
string str_tea = "select * from lab_user where user_type=2";
DropDownList drptea = (DropDownList)e.Item.Cells[3].FindControl("drptea");
co_cla.dr_Bind(str_tea, dropdownlist);
drptea.DataBind();
DropDownList drptea1 = (DropDownList)e.Item.Cells[4].FindControl("drptea1");
co_cla.dr_Bind(str_tea, dropdownlist1);
drptea1.DataBind();
DropDownList drptea2 = (DropDownList)e.Item.Cells[5].FindControl("drptea2");
co_cla.dr_Bind(str_tea, dropdownlist1);
drptea2.DataBind();
}
}

#7
zidu2007-05-27 17:59
最怕看代码,一头雾水,请指定drp...的数据源
1