问下怎么才能在一登录这个页面时,就绑定啊?
我在登录后,DropDownList没有绑定
大家来看啊 还没解决呢 我的代码如下:
<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();
}
}