看你要在哪里取了,如果是在datagrid事件中
e.Item.cells[i].Text,i为第n-1列或者直接DataGrid1...

解决方案 »

  1.   

    是这样,刚解决了datagrid中编辑状态下显示数据库绑定dropdownlist的问题,但dropdownlist的默认selectedindex是0,想让它默认选定是目前cell的值,所以才有此一问,上面的句子我试过,不报错,但取不回值来~~~
      

  2.   

    可以指定dropdownlist的选定值或选定文本。
      

  3.   

    DropDownList list = (DropDownList)e.Item.FindControl("DropDownList1");
    list.SelectedIndex = ...;
      

  4.   

    我知道设定dropdownlist的selectedindex的值就可以,但我无法确定为是值啊,如何才能知道datagrid的那个cell的值和那个dropdownlist的index相对应啊~~~~
      

  5.   

    list.SelectedIndex =e.Item.ItemIndex
      

  6.   

    我是这样做的:
    在c#中写一个取得当前值在别表框中的index的函数
    public int GetSelectedIndex(string strLx)
    {
    int i=0;
    if (strLx!=null)
    foreach(DataRow dr in ds.Tables["设置房间套型"].Rows)//当然,ds事先已经填充好了
    {
    if (strLx==dr["房间套型"].ToString())
    break;
    i++;
    }
    return i;
    }然后设置DropDowList的SelectIndex属性为GetSelectedIndex的返回值<asp:TemplateColumn HeaderText="房间套型">
    <HeaderStyle Width="20%"></HeaderStyle>
    <ItemTemplate>
    <asp:DropDownList ...>
    .
    .
    .
    SelectedIndex='<%# GetSelectedIndex((string)DataBinder.Eval(Container.DataItem."房间套型"))%>'/>
    .
    .
    .
    </asp:DropDownList>
    </ItemTemplate>
    </asp:TemplateColumn>《精通C#与ASP.NET程序设计》恒逸资讯编著(台湾的) 中国青年出版社
    294,范例5-15有详细的说明,你可以看一下
    不知为什么,这本书上的名字空间System.Data.SqlClient都写成System.Data.SQL,他的代码需要修改很多才能调试通过,不过有些方法是可取的