在网格视图的行编辑过程中下拉列表绑定 [英] drop down list binding during row editing of grid view

查看:95
本文介绍了在网格视图的行编辑过程中下拉列表绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个网格视图,其中有不同的字段,每个字段都是一个模板字段.在iten模板上,我有标签,在编辑项目模板上,有下拉dwn列表.
我的问题是gv可以完美地绑定,单击编辑"按钮需要我编辑网格视图...
但是没有填充下拉列表...意味着说如果我有一个激活的字段,是或否,并且标签的值为是,我想当我单击编辑按钮ddl时也应显示是自动填充的yes选项.我是否必须针对每个drop dwn列表在行数据绑定事件上执行此操作?

Hi,

I have a grid view in which there are different feilds and every field is a template field. On iten template I have labels and on edit item template there are drop dwn lists.
My prob is that gv is binding perfectly and on the click of edit button it is taking me to edit the grid view...
but the drop down lists are not populated... means say if i have a field active with Yes or no and label has its value as yes, I want when i click on the edit button ddl should also show the yes option populated automatically. Do i have to do this on row databound event for each drop dwn list ?

推荐答案


您必须使用列
设置SelectedValue 检查此示例.

Hi ,
You have to set SelectedValue with your columns
Check this Example .

<div>
           <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1"

        onrowdeleting="GridView1_RowDeleting">
        <Columns>
            <asp:BoundField DataField="dd" HeaderText="dd" SortExpression="dd" />
            <asp:TemplateField HeaderText="ddd" SortExpression="ddd">
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# Bind("ddd") %>'></asp:Label>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("ddd") %>'></asp:TextBox>
                </EditItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="cate" SortExpression="cate">
                <EditItemTemplate>
                    <asp:DropDownList ID="DropDownList1" runat="server"

                        DataSourceID="SqlDataSource12" DataTextField="cate" DataValueField="id"

                        SelectedValue="<%# Bind('cate') %>">
                    </asp:DropDownList>
                    <asp:SqlDataSource ID="SqlDataSource12" runat="server"

                        ConnectionString="<%


ConnectionStrings:testConnectionString%>" SelectCommand =" > < /asp:SqlDataSource > < /EditItemTemplate > < ItemTemplate > < asp:Label ID =" runat 服务器" 文本 <%#Bind(" )%>' > < /asp:Label > < /ItemTemplate > < /asp:TemplateField > < asp:CommandField ShowEditButton =" / < /列 > < /asp:GridView > < asp:SqlDataSource ID =" runat 服务器" span> ConnectionString =" <%
ConnectionStrings:testConnectionString %>" SelectCommand="SELECT * FROM [cate]"></asp:SqlDataSource> </EditItemTemplate> <ItemTemplate> <asp:Label ID="Label2" runat="server" Text='<%# Bind("cate") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:CommandField ShowEditButton="True" /> </Columns> </asp:GridView> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%


ConnectionStrings:testConnectionString%>" SelectCommand =" 选择*来自[View_1]" < /asp:SqlDataSource > < br > < asp:Button ID =" runat 服务器" onclick Button1_Click" 文本 按钮" span> =" 高度:26像素" / > < /div >
ConnectionStrings:testConnectionString %>" SelectCommand="SELECT * FROM [View_1]"></asp:SqlDataSource> <br /> <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" style="height: 26px" /> </div>



最好的问候
米特瓦里(M.Mitwalli)



Best Regards
M.Mitwalli


这篇关于在网格视图的行编辑过程中下拉列表绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆