请帮忙解决这个网格视图问题 [英] Please help to solve this grid view problem

查看:55
本文介绍了请帮忙解决这个网格视图问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Everyone,



我有一个网格视图如下。

Hello Everyone,

I have a grid view as follows.

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
                   BackColor="White" BorderColor="#999999" BorderStyle="None" BorderWidth="1px"
                   CellPadding="3" DataSourceID="SqlDataSource1" GridLines="Vertical"
                   Width="744px" onselectedindexchanged="GridView1_SelectedIndexChanged"
                   ShowFooter="True" Height="269px">
                   <AlternatingRowStyle BackColor="#DCDCDC" />
                   <Columns>
                       <asp:TemplateField HeaderText="Product" SortExpression="Product">
                           <EditItemTemplate>
                               <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Product") %>'></asp:TextBox>
                           </EditItemTemplate>
                           <ItemTemplate>
                               <asp:CheckBox ID="CheckBox1" runat="server" />
                               <asp:Label ID="Label1" runat="server" Text='<%# Bind("Product") %>'></asp:Label>
                           </ItemTemplate>
                       </asp:TemplateField>
                       <asp:TemplateField HeaderText="Quantity" FooterText="Total Amount">
                           <FooterTemplate>
                               <asp:Button ID="Button3" runat="server" onclick="Button3_Click"
                                   Text="Total Amount" />
                           </FooterTemplate>
                           <ItemTemplate>
                               <asp:TextBox ID="TextBox2" runat="server" ontextchanged="TextBox2_TextChanged" AutoPostBack="true"></asp:TextBox>
                               <br />
                               <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Style="display: none" />
                               <asp:PlaceHolder ID="PlaceHolder1" runat="server">  </asp:PlaceHolder>
                           </ItemTemplate>
                       </asp:TemplateField>
                       <asp:TemplateField HeaderText="Amount">
                           <FooterTemplate>
                               <asp:Label ID="Label9" runat="server"></asp:Label>
                           </FooterTemplate>
                           <ItemTemplate>
                               <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
                           </ItemTemplate>
                       </asp:TemplateField>
                       <asp:TemplateField HeaderText="Status">
                           <ItemTemplate>
                               <asp:DropDownList ID="DropDownList1" runat="server">
                                   <asp:ListItem>New</asp:ListItem>
                                   <asp:ListItem>Refurbished</asp:ListItem>
                               </asp:DropDownList>
                           </ItemTemplate>
                       </asp:TemplateField>
                   </Columns>
                   <FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
                   <HeaderStyle BackColor="Silver" Font-Bold="True" ForeColor="Black" />
                   <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
                   <RowStyle BackColor="#EEEEEE" ForeColor="Black" />
                   <SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
                   <SortedAscendingCellStyle BackColor="#F1F1F1" />
                   <SortedAscendingHeaderStyle BackColor="#0000A9" />
                   <SortedDescendingCellStyle BackColor="#CAC9C9" />
                   <SortedDescendingHeaderStyle BackColor="#000065" />
               </asp:GridView>
               <asp:SqlDataSource ID="SqlDataSource1" runat="server"
                   ConnectionString="<%$ ConnectionStrings:FSPL_AMCConnectionString %>"
                   SelectCommand="SELECT DISTINCT [Product]  FROM [Products]"></asp:SqlDataSource>
               <asp:Button ID="Button2" runat="server" style="font-weight: 700"
                   Text="Add to FSPL Inventory" onclick="Button2_Click" />
           </td>
           <td valign="top">
               <asp:GridView ID="GridView2" runat="server" Height="16px" Width="413px"
                   AutoGenerateColumns="False" BackColor="White" BorderColor="#999999"
                   BorderStyle="Solid" BorderWidth="1px" CellPadding="3" ForeColor="Black"
                   GridLines="Vertical">
                   <AlternatingRowStyle BackColor="#CCCCCC" />
                   <Columns>
                       <asp:TemplateField HeaderText="Invoice Number">
                           <EditItemTemplate>
                               <asp:TextBox ID="TextBox1" runat="server"
                                   Text='<%# Bind("[Invoice Number]") %>'></asp:TextBox>
                           </EditItemTemplate>
                           <ItemTemplate>
                               <asp:ImageButton ID="ImageButton1" runat="server"
                                   ImageUrl="~/images/edit.png" />
                               <asp:Label ID="Label1" runat="server" Text='<%# Bind("[Invoice Number]") %>'></asp:Label>
                           </ItemTemplate>
                       </asp:TemplateField>
                       <asp:TemplateField HeaderText="Date">
                           <EditItemTemplate>
                               <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("Date") %>'></asp:TextBox>
                           </EditItemTemplate>
                           <ItemTemplate>
                               <asp:Label ID="Label2" runat="server" Text='<%# Bind("Date") %>'></asp:Label>
                           </ItemTemplate>
                       </asp:TemplateField>
                       <asp:TemplateField HeaderText="Total Amount">
                           <EditItemTemplate>
                               <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("[Total Amount]") %>'></asp:TextBox>
                           </EditItemTemplate>
                           <ItemTemplate>
                               <asp:Label ID="Label3" runat="server" Text='<%# Bind("[Total Amount]") %>'></asp:Label>
                           </ItemTemplate>
                       </asp:TemplateField>
                   </Columns>
                   <FooterStyle BackColor="#CCCCCC" />
                   <HeaderStyle BackColor="Silver" Font-Bold="True" ForeColor="Black" />
                   <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
                   <SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
                   <SortedAscendingCellStyle BackColor="#F1F1F1" />
                   <SortedAscendingHeaderStyle BackColor="#808080" />
                   <SortedDescendingCellStyle BackColor="#CAC9C9" />
                   <SortedDescendingHeaderStyle BackColor="#383838" />
               </asp:GridView>





当我选中复选框并在数量上写下数量的文本数量然后是那个textboes数量动态生成文本已更改。当我在动态文本框中编写序列号并插入数据库时​​。在数据库中,没有插入正确的序列号。这是我的插入代码



when i m checking the checkbox and write the number of quantity in quantity textboes then that number of textboes generating dynamically on text changed. when i write the serial no in the dynamic textboxes and insert into the database. In database the correct serial number is not inserting. this my insert code

protected void Button2_Click(object sender, EventArgs e)
    {
        for (int i = 0; i < GridView1.Rows.Count;i++ )
        {
            

            Label lab = (Label)GridView1.Rows[i].FindControl("Label1");
            Label ColTotal = (Label)GridView1.FooterRow.FindControl("Label9");
            TextBox quantity = (TextBox)GridView1.Rows[i].FindControl("TextBox2");
            TextBox TAmount = (TextBox)GridView1.Rows[i].FindControl("TextBox3");
            string amount = quantity.Text;
            DropDownList ddl = (DropDownList)GridView1.Rows[i].FindControl("DropDownList1");

            CheckBox chk = (CheckBox)GridView1.Rows[i].Cells[0].FindControl("Checkbox1");
            if (chk.Checked == true)
            {
                if (quantity.Text != "")
                {



                    for (int j = 0; j < Convert.ToInt16(quantity.Text); j++)
                    {
                        con.Open();

                        string query1 = "insert into Inventory ([Invoice Number],Product,[Serial Number],Amount,Status) values('" + TextBox5.Text + "', '" + lab.Text + "','" + Request.Form["Textbox" + j.ToString().Trim()] + "','" + Convert.ToInt32(TAmount.Text) / Convert.ToInt32(quantity.Text) + "','" + ddl.SelectedValue + "')";
                        SqlCommand cmd = new SqlCommand(query1, con);
                        cmd.ExecuteNonQuery();
                        con.Close();

                    }
                }
                con.Open();
                string query = "insert into FSPL_Inventory ([Invoice Number],[Date],[Total Amount]) values('" + TextBox5.Text + "','" + Label7.Text + "','" + ColTotal.Text + "')";
                SqlCommand comd = new SqlCommand(query, con);
                comd.ExecuteNonQuery();
                con.Close();
                bind();

               

                }









            }
        }



请帮忙解决这个问题。


Please help to solve this.

推荐答案

ConnectionStrings:FSPL_AMCConnectionString%>
SelectCommand = SELECT DISTINCT [Product] FROM [产品] > < / asp:SqlDataSource >
< asp:按钮ID = < span class =code-string> Button2 runat = server style = font-weight:700
Text = 添加到FSPL库存 onclick = Button2_Click />
< / td >
< td valign = top >
< asp:GridView ID = GridView2 runat = server高度= 16px宽度= 413px
AutoGenerateColumns = False BackColor = 白色 BorderColor = #999999
BorderStyle = 实体 BorderWidth = 1px CellPadding = < span class =code-string> 3 ForeColor = 黑色
GridLines = 垂直 >
< AlternatingRowStyle BackColor = #CCCCCC />
< Columns>
< asp:TemplateField HeaderText = 发票编号 >
< EditItemTemplate>
< asp:TextBox ID = TextBox1 runat = server
Text = ' <%#Bind([Invoice Number])%>' > < / asp:TextBox >
< / EditItemTemplate >
< ; ItemTemplate中>
< asp:ImageButton ID = ImageButton1 runat = server
ImageUrl = 〜/ images / edit.png />
< asp:标签ID = Label1 runat = server Text = ' <%#Bind([发票号码])%>' > < ; / asp:标签 >
< / ItemTemplate >
</asp:TemplateField>
< ;asp:TemplateField HeaderText=\"Date\">
<EditItemTemplate>
<asp:TextBox ID=\"TextBox2\" runat=\"server\" Text='<%# Bind(\"Date\") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID=\"Label2\" runat=\"server\" Text='<%# Bind(\"Date\") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText=\"Total Amount\">
<EditItemTemplate>
<asp:TextBox ID=\"TextBox3\" runat=\"server\" Text='<%# Bind(\"[Total Amount]\") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID=\"Label3\" runat=\"server\" Text='<%# Bind(\"[Total Amount]\") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle Back Color=\"#CCCCCC\" />
<HeaderStyle BackColor=\"Silver\" Font-Bold=\"True\" ForeColor=\"Black\" />
<PagerStyle BackColor=\"#999999\" ForeColor=\"Black\" HorizontalAlign=\"Center\" />
<SelectedRowStyle BackColor=\"#000099\" Font-Bold=\"True\" ForeColor=\"White\" />
<SortedAscendingCellStyle BackColor=\"#F1F1F1\" />
<SortedAscendingHeaderStyle BackColor=\"#808080\" />
<SortedDescendingCellStyle BackColor=\"#CAC9C9\" />
<SortedDescendingHeaderStyle BackColor=\"#383838\" />
</asp:GridView>
ConnectionStrings:FSPL_AMCConnectionString %>" SelectCommand="SELECT DISTINCT [Product] FROM [Products]"></asp:SqlDataSource> <asp:Button ID="Button2" runat="server" style="font-weight: 700" Text="Add to FSPL Inventory" onclick="Button2_Click" /> </td> <td valign="top"> <asp:GridView ID="GridView2" runat="server" Height="16px" Width="413px" AutoGenerateColumns="False" BackColor="White" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" CellPadding="3" ForeColor="Black" GridLines="Vertical"> <AlternatingRowStyle BackColor="#CCCCCC" /> <Columns> <asp:TemplateField HeaderText="Invoice Number"> <EditItemTemplate> <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("[Invoice Number]") %>'></asp:TextBox> </EditItemTemplate> <ItemTemplate> <asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/images/edit.png" /> <asp:Label ID="Label1" runat="server" Text='<%# Bind("[Invoice Number]") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Date"> <EditItemTemplate> <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("Date") %>'></asp:TextBox> </EditItemTemplate> <ItemTemplate> <asp:Label ID="Label2" runat="server" Text='<%# Bind("Date") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Total Amount"> <EditItemTemplate> <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("[Total Amount]") %>'></asp:TextBox> </EditItemTemplate> <ItemTemplate> <asp:Label ID="Label3" runat="server" Text='<%# Bind("[Total Amount]") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> </Columns> <FooterStyle BackColor="#CCCCCC" /> <HeaderStyle BackColor="Silver" Font-Bold="True" ForeColor="Black" /> <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" /> <SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" /> <SortedAscendingCellStyle BackColor="#F1F1F1" /> <SortedAscendingHeaderStyle BackColor="#808080" /> <SortedDescendingCellStyle BackColor="#CAC9C9" /> <SortedDescendingHeaderStyle BackColor="#383838" /> </asp:GridView>





when i m checking the checkbox and write the number of quantity in quantity textboes then that number of textboes generating dynamically on text changed. when i write the serial no in the dynamic textboxes and insert into the database. In database the correct serial number is not inserting. this my insert code



when i m checking the checkbox and write the number of quantity in quantity textboes then that number of textboes generating dynamically on text changed. when i write the serial no in the dynamic textboxes and insert into the database. In database the correct serial number is not inserting. this my insert code

protected void Button2_Click(object sender, EventArgs e)
    {
        for (int i = 0; i < GridView1.Rows.Count;i++ )
        {
            

            Label lab = (Label)GridView1.Rows[i].FindControl("Label1");
            Label ColTotal = (Label)GridView1.FooterRow.FindControl("Label9");
            TextBox quantity = (TextBox)GridView1.Rows[i].FindControl("TextBox2");
            TextBox TAmount = (TextBox)GridView1.Rows[i].FindControl("TextBox3");
            string amount = quantity.Text;
            DropDownList ddl = (DropDownList)GridView1.Rows[i].FindControl("DropDownList1");

            CheckBox chk = (CheckBox)GridView1.Rows[i].Cells[0].FindControl("Checkbox1");
            if (chk.Checked == true)
            {
                if (quantity.Text != "")
                {



                    for (int j = 0; j < Convert.ToInt16(quantity.Text); j++)
                    {
                        con.Open();

                        string query1 = "insert into Inventory ([Invoice Number],Product,[Serial Number],Amount,Status) values('" + TextBox5.Text + "', '" + lab.Text + "','" + Request.Form["Textbox" + j.ToString().Trim()] + "','" + Convert.ToInt32(TAmount.Text) / Convert.ToInt32(quantity.Text) + "','" + ddl.SelectedValue + "')";
                        SqlCommand cmd = new SqlCommand(query1, con);
                        cmd.ExecuteNonQuery();
                        con.Close();

                    }
                }
                con.Open();
                string query = "insert into FSPL_Inventory ([Invoice Number],[Date],[Total Amount]) values('" + TextBox5.Text + "','" + Label7.Text + "','" + ColTotal.Text + "')";
                SqlCommand comd = new SqlCommand(query, con);
                comd.ExecuteNonQuery();
                con.Close();
                bind();

               

                }









            }
        }



Please help to solve this.


Please help to solve this.


这篇关于请帮忙解决这个网格视图问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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