gridview中下拉框对当前行数据的绑定

.Net技术 码拜 9年前 (2015-02-14) 1276次浏览 0个评论

gridview中下拉框对当前行数据的绑定
在每个负责人下面有不同的员工,而员工的选择对应着一个负责人-员工表,如何将将下拉框绑定负责人-员工表,并且在点击一个按钮后将员工这一列插入到公司表中
加入了dropdownList但是不知道怎么和另外一张表绑定并且与当前行中的负责人关联?
谢谢!

 
gridview中下拉框对当前行数据的绑定
你不如等点了”编辑”,再把它变成下拉列表,并且绑定当前行的数据
你这明显每个下拉列表里要绑定的内容不一样,一开始就都加载出来效率低,而且没啥用
gridview中下拉框对当前行数据的绑定
20分
在OnItemDataBound事件里边,用FindControl 找到你的控件 dropList ,然后取得你的数据源,然后绑定到dropList 上!
gridview中下拉框对当前行数据的绑定
20分
GridView中下拉框对当前行的绑定问题
//GridView设置
<asp:GridView ID=”GridView1″ runat=”server” AllowPaging=”True” AllowSorting=”True”
                                    AutoGenerateColumns=”False” BackColor=”#DEBA84″ 
            BorderColor=”#DEBA84″ BorderStyle=”None”
                                    BorderWidth=”1px” CellPadding=”3″ CellSpacing=”2″ DataKeyNames=”产品编号” 
                                    ShowFooter=”True” Width=”642px” 
            OnRowCreated=”GridView1_RowCreated” OnRowDataBound=”GridView1_RowDataBound” 
            onpageindexchanging=”GridView1_PageIndexChanging” PageSize=”5″ 
            onrowediting=”GridView1_RowEditing” onrowupdating=”GridView1_RowUpdating” 
            style=”font-size: small”>
                                    <FooterStyle BackColor=”#F7DFB5″ ForeColor=”#8C4510″ />
                                    <Columns>
                                        <asp:TemplateField HeaderText=”产品名称”>
                                            <ItemTemplate>
                                       <%#HightLightText((string)Eval(“产品”), this.tbSearch.Text.Trim())%>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                        <asp:BoundField DataField=”单价” HeaderText=”单价” SortExpression=”单价” 
                                            ReadOnly=”True” />
                                        <asp:BoundField DataField=”库存量” HeaderText=”库存量” SortExpression=”库存量” 
                                            ReadOnly=”True” />
                                        <asp:BoundField DataField=”已订购量” HeaderText=”已订购量” SortExpression=”已订购量” 
                                            ReadOnly=”True” />
                                        <asp:TemplateField HeaderText=”订货金额” SortExpression=”订货金额”>
                                            <EditItemTemplate>
                                             <asp:Label ID=”Label1″ runat=”server” Text=”<%# Eval(“订货金额”, “{0:c}”) %>”></asp:Label>
                                            </EditItemTemplate>
                                            <FooterTemplate>
                                                <asp:Label ID=”OrderTotalLabel” runat=”server” Font-Underline=”True” ForeColor=”Red”></asp:Label>
                                            </FooterTemplate>
                                            <ItemTemplate>
                                                <asp:Label ID=”Label1″ runat=”server” Text=”<%# Bind(“订货金额”, “{0:c}”) %>”></asp:Label>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                        <asp:TemplateField HeaderText=”是否停售”>
                                         <EditItemTemplate>
                                    <asp:DropDownList ID=”ddlSellState” runat=”server” AutoPostBack=”True”>
                                        <asp:ListItem Value=”True”>停售</asp:ListItem>
                                        <asp:ListItem Value=”False”>不停售</asp:ListItem>
                                    </asp:DropDownList>
                                </EditItemTemplate>
                                <ItemTemplate>
                                    <asp:Label ID=”Label4″ runat=”server” Text=”<%# Eval(“SellState”) %>”></asp:Label>
                                </ItemTemplate>
                                        </asp:TemplateField>
                                        <asp:CommandField HeaderText=”设置” ShowEditButton=”True” />
                                    </Columns>
                                    <RowStyle BackColor=”#FFF7E7″ ForeColor=”#8C4510″ />
                                    <SelectedRowStyle BackColor=”#C0FFC0″ Font-Bold=”True” ForeColor=”Black” />
                                    <PagerStyle ForeColor=”#8C4510″ HorizontalAlign=”Center” />
                                    <HeaderStyle BackColor=”#A55129″ Font-Bold=”True” ForeColor=”White” />
                                </asp:GridView>
//cs页面关联下拉框绑定问题
 protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        int ID=int.Parse(GridView1.DataKeys[e.RowIndex].Value.ToString());
        bool PaperState = bool.Parse(((DropDownList)GridView1.Rows[e.RowIndex].FindControl(“ddlSellState”)).SelectedValue);
        string strsql = “UPDATE tb_OrderForm SET 是否停售 = @SellState WHERE 产品编号= @ID”;
        SqlConnection conn = new SqlConnection(ConfigurationSettings.AppSettings[“ConnectionString”]);
        conn.Open();
        SqlCommand comm = new SqlCommand(strsql, conn);
        comm.Parameters.Add(new SqlParameter(“@ID”, SqlDbType.Int, 4));
        comm.Parameters[“@ID”].Value = ID;
        comm.Parameters.Add(new SqlParameter(“@SellState”, SqlDbType.Bit, 1));
        comm.Parameters[“@SellState”].Value = PaperState;
        if (Convert.ToInt32(comm.ExecuteNonQuery()) > 0)
        {
            Response.Write(“<script language=javascript>alert(“设置成功!”);location=”Default.aspx”</script>”);
        }
        else
        {
            Response.Write(“<script language=javascript>alert(“设置失败!”);location=”Default.aspx”</script>”);
        }
        //取消编辑操作
        GridView1.EditIndex = -1;
        //调用自定义方法DbBind()重新绑定GridView控件中信息
        DbBind();
    }
gridview中下拉框对当前行数据的绑定
引用 1 楼:

你不如等点了”编辑”,再把它变成下拉列表,并且绑定当前行的数据
你这明显每个下拉列表里要绑定的内容不一样,一开始就都加载出来效率低,而且没啥用

+1


CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明gridview中下拉框对当前行数据的绑定
喜欢 (0)
[1034331897@qq.com]
分享 (0)

文章评论已关闭!