|
|
你不如等点了”编辑”,再把它变成下拉列表,并且绑定当前行的数据
你这明显每个下拉列表里要绑定的内容不一样,一开始就都加载出来效率低,而且没啥用 |
|
20分 |
在OnItemDataBound事件里边,用FindControl 找到你的控件 dropList ,然后取得你的数据源,然后绑定到dropList 上!
|
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(); } |
+1 |