使用自定义绑定,默认的Datagrid是绑定数据表中所有列,通过属性生成器来设置

解决方案 »

  1.   

    在DropDownList 的SelectedIndexChanged事件中,DropDownList的AutoPostBack属性设为true
    private void DropDownList_SelectedIndexChanged(object sender, System.EventArgs e)
    {
    得到gcblx我不知道类型,假设为整型
    int gcblx = Int32.Parse( DropDownList1.SelectedItem.Text );
    在根据gcblx邦定你DataGrid1
    string strSql = "select * from youtable where gcblx="+gcblx.ToString;
    dsCommand.SelectCommand = new SqlCommand( strSql , conn );
    DataTable dataTable = new DataTable;
    dsCommand.Fill(dataTable);
    this.DataGrid1.DataSource = dataTable;
    this.DataGrid1.DataBind();
    }
      

  2.   

    在DropDownList 的SelectedIndexChanged事件中,DropDownList的AutoPostBack属性设为true
    然后绑定DropDownList的Value为ID建议最好在ProjectInfo中是ID列而不是gcblx列,这样实现起来就更加的方便了。
    然后在绑定到DataGrid中的时候这样来写SQL语句
    string strSQL="select * from ProjectInfo, ProjectType where ProjectInfo.gcblx=ProjectType .gcblx";
    绑定到DataGrid中去就可以了。至于可编辑那就要对DataGrid的一些事件做动作。你先看看能不能把上面的问题解决,解决不掉给我发消息我给你具体大的源码!!
      

  3.   

    使用DataGrid动态绑定DropDownList 
    http://www.csdn.net/Develop/read_article.asp?id=26590
      

  4.   

    <asp:TemplateColumn headertext="科目">
    <ItemTemplate>
    <asp:Label id="lblLabelName" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Subject") %>'>
    </asp:Label>
    </ItemTemplate>
    <EditItemTemplate>
    <asp:DropDownList id="ddl" runat="server"></asp:DropDownList>
    </EditItemTemplate>
    </asp:TemplateColumn>
    private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
    {
    if(e.Item.ItemType==ListItemType.EditItem)
    {
    DropDownList ddl1=(DropDownList) e.Item.FindControl("ddl");
    //定义DataSource
    ddl1.DataSource=mydatasource; ddl1.DataTextField="gcblx";
    ddl1.DataValueField="gcblx";
    ddl1.DataBind();
    string role=DataBinder.Eval(e.Item.DataItem,"gcblx").ToString();
    ddl1.Items.FindByText(role).Selected=true; }
    }