使用模版列,设置selectedindex的值

解决方案 »

  1.   

    <EditItemTemplate>
    <asp:DropDownList id=DropDownList1 runat="server" Width="101px" SelectedIndex='<%# DataBinder.Eval(Container, "DataItem.OPERATOR_CLASS").ToString()=="A"? 0:1 %>'>
    <asp:ListItem Value="A">管理员</asp:ListItem>
    <asp:ListItem Value="O">操作员</asp:ListItem>
    </asp:DropDownList>
    </EditItemTemplate>
      

  2.   

    我用的就是模板列啊。在哪个事件里设置selectedindex的值呢?
      

  3.   

    kinglht(爱新觉罗至尊宝) ( ) 兄弟。。我的DropDownList的DataSource是一个方法的返回值。返回一个DataView
      

  4.   

    在窗体里托放一个DataView控件,不指定DropDownList的DataSource,然后象上面那样做!
      

  5.   

    <asp:TemplateColumn HeaderText="负责者">
    <HeaderStyle Width="50px"></HeaderStyle>
    <ItemTemplate>
    <asp:Label id=Label7 runat="server" Width="72px" Height="6px" Text='<%# DataBinder.Eval(Container.DataItem, "Principal") %>'>
    </asp:Label>
    </ItemTemplate>
    <EditItemTemplate>
    <asp:DropDownList id=DropDownList3 runat="server" Width="80px" Height="23px" DataValueField="Name" DataTextField="Name" DataSource="<%# WorkManDataBind() %>">
    </asp:DropDownList>
    </EditItemTemplate>
    </asp:TemplateColumn>这是我的html下面看到的代码。请 kinglht(爱新觉罗至尊宝) ( )兄。。帮忙啊:)
      

  6.   

    使用DROPDOWNLIST的FINDBYVALUE或FINDBYTEXT属性
      

  7.   

    我刚才试了一下,数据源是用一个函数生成的,返回值是DataView,把你的
    <EditItemTemplate>
    <asp:DropDownList id=DropDownList3 runat="server" Width="80px" Height="23px" DataValueField="Name" DataTextField="Name" DataSource="<%# WorkManDataBind() %>">
    </asp:DropDownList>
    </EditItemTemplate>
    改成
    <EditItemTemplate>
    <asp:DropDownList id="DropDownList1" runat="server" Width="89px" SelectedIndex='<%# DataBinder.Eval(Container, "DataItem.布尔值").ToString()=="True"? 0:1 %>'>
    <asp:ListItem Value="1">真</asp:ListItem>
    <asp:ListItem Value="0">假</asp:ListItem>
    </asp:DropDownList>
    </EditItemTemplate>
    我只是举个例子,我的DropDownList只有两项(真假),你可以根据你自己的数据改改!希望对你有帮助!!
      

  8.   

    you can use "findbyvalue" or "findbytext"/
    when you clicked you "edit" button ,you can get you selectitemindex,and you can get you dropdownlist text(or value) ,save it in you session.
    when you bound you dropdownlist ,you can use the session'value find the dpl's itemindex.
    All of then ,you should write on DG_editcommand event.
      

  9.   

    you can use "findbyvalue" or "findbytext"/
    when you clicked you "edit" button ,you can get you selectitemindex,and you can get you dropdownlist text(or value) ,save it in you session.
    when you bound you dropdownlist ,you can use the session'value find the dpl's itemindex.
    All of then ,you should write on DG_editcommand event.
      

  10.   

    yohomonkey(ht) 兄。。你有试过你说的这个方法吗?
    我试过了。。在editcommand事件里跟本就无法得到在模板列里edit模式
    下的DropDownList的selecitemindex..如果使用
    e.item.cell[8].findcontrol("DropDownList1")就是出现对象没有引用
    到实例的错误。。给我的感觉就是在editcommand事件没有执行完毕的话
    datagrid的每一个列还都没有变成edit的模式。也无法得到在edit模式下
    的DropDownList
      

  11.   

    kinglht(爱新觉罗至尊宝) ( ) 
    谢谢你热心的帮助我我已经找到了解决的办法:)
    通过给SelectIndex返回一个值。就像给Datasource返回一个值一样。
    就可以定位到原来的值上:)
      

  12.   

    能否给出你DataGrid中可以绑定DropDownList的代码