使用模板列,在item里写<asp:dropdownlist _____/>之类的就加上了控件,然后写代码进行绑定。

解决方案 »

  1.   

    使用模板后可以实现,但如何实现当前行绑定的dropdownlist的被选择项就是该列原来的值,因为有这种情况,用户修改时,整个行都处于修改状态,但用户有可能不修改绑定列所在列原来的值,如绑定列的被选择项不是原来的值,用户一定选择更新那可能就连原来不想修改的这项也被改为绑定列默认的选定项。
      

  2.   

    in BindGrid()
    for(int i=0;i<num;i++)
    {
    Label La=(Label)(DataGrid1.Items[i].FindControl("Label1"));
    if(La!=null)
    {
    if(La.Text[0]=='1')La.Text="1111";
    if(La.Text[0]=='2')La.Text="2222";
    if(La.Text[0]=='3')La.Text="3333";
    if(La.Text[0]=='4')La.Text="4444";
    } }in edit()
    int index=0;
    Label La=(Label)(DataGrid1.Items[e.Item.ItemIndex].FindControl("Label1"));
    if(La!=null)
    {
    if(La.Text=="1111")index=0;
    if(La.Text=="2222")index=1;
    if(La.Text=="3333")index=2;
    if(La.Text=="4444")index=3;
    }

    DataGrid1.EditItemIndex = (int)e.Item.ItemIndex;
    BindGrid();
    //((TextBox)e.Item.Cells[2].Controls[0]).Width=Unit.Pixel(22);
    DataGrid1.EditItemIndex=e.Item.ItemIndex;
    DropDownList Dr=(DropDownList)(DataGrid1.Items[DataGrid1.EditItemIndex].FindControl("DropDownList1"));
    Dr.Items.Add(new ListItem("1111", "1"));
    Dr.Items.Add(new ListItem("2222", "2"));
    Dr.Items.Add(new ListItem("3333", "3"));
    Dr.Items.Add(new ListItem("4444", "4"));
    Dr.SelectedIndex = index;in update()
    myCommand.Parameters.Add(new SqlParameter("@Secuty", SqlDbType.Char,20));

    DropDownList Dr=(DropDownList)(DataGrid1.Items[DataGrid1.EditItemIndex].FindControl("DropDownList1"));
    if(Dr!=null)
    {
    int index=Dr.SelectedIndex;
    if(index==0)myCommand.Parameters["@Secuty"].Value = "1";
    if(index==1)myCommand.Parameters["@Secuty"].Value = "2";
    if(index==2)myCommand.Parameters["@Secuty"].Value = "3";
    if(index==3)myCommand.Parameters["@Secuty"].Value = "4";
    }
      

  3.   

    用模板列可以添加DropDownList,RadioBox等.
      

  4.   

    出错:System.Web.UI.WebControls.ListItem”并不包含对“DataBinding”的定义
    <asp:ListItem Selected="True" Value='<%#DataBinder.EvalContainer.DataItem,"state")%>'> </asp:ListItem><asp:TemplateColumn>
    <EditItemTemplate>
    <asp:DropDownList id="ddl" Width="96px" Runat="server">
    <asp:ListItem Selected="True" Value='<%# DataBinder.Eval(Container.DataItem,"state")%>'>
    </asp:ListItem>
    <asp:ListItem Value="1">尚未合作</asp:ListItem>
    <asp:ListItem Value="2">已经合作</asp:ListItem>
    <asp:ListItem Value="3">正在洽谈</asp:ListItem>
    </asp:DropDownList>
    </EditItemTemplate>
    </asp:TemplateColumn>
    后端.cs 程序:
    // string state=((ListBox)e.Item.Cells[9].Controls[0]).SelectedItem.Value;
    string state=((DropDownList)(dg2.Items[dg2.EditItemIndex].FindControl("ddl"))).SelectedItem.Value;
    2个都不行