代码是这么写的:
<EditItemTemplate>
<asp:DropDownList Runat="server" ID="EditDeptName" Width="90%" DataSource='<%# dept_name_array%>' SelectedIndex='<%# b_cm.get_selected_index(dept_value_array,DataBinder.Eval(Container.DataItem,"dept_id").ToString())%>' > </asp:DropDownList>
</EditItemTemplate>
--------------------------------------
生成的HTML:<option value="协调部">协调部</option>
<option value="物流部aa">物流部aa</option>
<option selected="selected" value="分公司">分公司</option>--------------------------------------------------------
现在想把value的值改成一些数字,如1,2,3等,如何才能实现这样的呢?
<option value="1">协调部</option>
<option value="2">物流部aa</option>
<option selected="selected" value="3">分公司</option>
多谢~~

解决方案 »

  1.   

    在ItemCreated事件中绑定就行了。
      

  2.   

    DataTextField
    DataValueField
    设定不同的字段
    http://www.cnblogs.com/lovecherry/archive/2005/03/25/125525.html
      

  3.   

    绑定时设置
    DataTextField =>option显示的字符
    DataValueField =>option的值
      

  4.   

    也可以用js
    http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/objects/option.asp
      

  5.   

    <EditItemTemplate>
    <asp:DropDownList 
    Runat="server" 
    ID="EditDeptName" 
    Width="90%"
    DataTextField ="textcol"
    DataValueField ="valuecol"
    DataSource='<%# dept_name_array%>' 
    SelectedIndex='<%# b_cm.get_selected_index(dept_value_array,DataBinder.Eval(Container.DataItem,"dept_id").ToString())%>' >
    </asp:DropDownList>
    </EditItemTemplate>
      

  6.   

    偶对asp.net不是太熟悉,上面的几个兄弟能详细的说说吗?
    我是这么改的,但是提示这一行“d.DataValueField = "dept_id";”:未将对象引用设置到对象的实例
    private void dg_employees_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
    {
    this.dg_employees.EditItemIndex = e.Item.ItemIndex;
    this.data_bind();
    DropDownList d = (DropDownList)e.Item.FindControl("EditDeptName");
    d.DataValueField = "dept_id";
    }
      

  7.   

    <EditItemTemplate>
    <asp:DropDownList Runat="server" ID="EditDeptName" Width="90%" DataSource='<%# dept_name_array%>' SelectedIndex='<%# b_cm.get_selected_index(dept_value_array,DataBinder.Eval(Container.DataItem,"dept_id").ToString())%>' > </asp:DropDownList>
    </EditItemTemplate>
    明白你的意思了,其实你完全可以查询数据库时就改变了,这样读出来就可以了!
    比如
    select case dept_name_array when "协调部" then '1' when 物流部aa then '2' end as sex from TABLE1
      

  8.   

    还是不行啊~~~
    我改成这样了
    ----------------
    <EditItemTemplate>
    <asp:DropDownList Runat="server" ID="EditDeptName" Width="90%" DataTextField ="dept_name" DataValueField="dept_id" DataSource='<%# dept_name_array%>' SelectedIndex='<%# b_cm.get_selected_index(dept_value_array,DataBinder.Eval(Container.DataItem,"dept_id").ToString())%>' >
    </asp:DropDownList>
    </EditItemTemplate>
    提示:DataBinder.Eval:“System.String”不包含名称为 dept_name 的属性。
    -------------------------
    楼上的兄弟:
    dept_name_array本身是个数组,我的SQL语句不这样写的,部门名称和部门ID是2个字段~~
      

  9.   

    <EditItemTemplate>
    <asp:DropDownList ID="ddl_DEPKBKNO1" Runat="server" Width="100%" SelectedIndex='<%# b_cm.get_selected_index(dept_value_array,DataBinder.Eval(Container.DataItem,"dept_id").ToString())%>'>
           <asp:ListItem value="1">协调部</asp:ListItem>
    <asp:ListItem value="2">物流部aa</asp:ListItem>
     <asp:ListItem selected="selected" value="3">分公司</asp:ListItem>

    </asp:DropDownList>
    </EditItemTemplate>
      

  10.   

    还是不行啊~~~
    我改成这样了
    ----------------
    <EditItemTemplate>
    <asp:DropDownList Runat="server" ID="EditDeptName" Width="90%" DataTextField ="dept_name" DataValueField="dept_id" DataSource='<%# dept_name_array%>' SelectedIndex='<%# b_cm.get_selected_index(dept_value_array,DataBinder.Eval(Container.DataItem,"dept_id").ToString())%>' >
    </asp:DropDownList>
    </EditItemTemplate>
    提示:DataBinder.Eval:“System.String”不包含名称为 dept_name 的属性。
    -------------------------
    楼上的兄弟:
    dept_name_array本身是个数组,我的SQL语句不这样写的,部门名称和部门ID是2个字段~~字段名错了!