You must Sign In to post a response.
  • Category: ASP.NET

    If i enter quantity, my first row is getting affected

    if i enter quantity my first row is affected in asp.net


    i enter the quantity my first row is affected but i choose second row.
    now i choose the third row am getting the error message.
    if i select the row i need to change the quantity and show the quantity in the gridview.



    protected void txtqty_TextChanged(object sender, EventArgs e)
    {
    BindListView();
    foreach (GridViewRow row in ddsales.Rows)
    {
    row.Cells[3].Text = txtqty.Text;
    double mr, wt, totlrp, mpr;
    mr = Convert.ToDouble((row.FindControl("lblmrp") as Label).Text);
    {
    wt = double.Parse(txtqty.Text);
    totlrp = mr * wt;
    ((row.FindControl("lblmrp") as Label).Text) = Convert.ToString(totlrp);
    txtbillamountcash.Text = Convert.ToString(totlrp);
    }
    break;
    }

    Calc();
    }

    private void Calc()
    {
    double foottotal = 0;
    foreach (GridViewRow dr in ddsales.Rows)
    {
    double price = Convert.ToDouble(((Label)dr.FindControl("lblmrp")).Text);
    foottotal = foottotal + price;
    }
    if (txtqty.Text != "")
    {
    foreach (GridViewRow dr in ddsales.Rows)
    {

    foreach (GridViewRow row in ddsales.Rows)
    {
    if (row.RowIndex == ddsales.SelectedIndex)
    {
    double mr, wt, totlrp, mpr;
    mr = Convert.ToDouble((row.FindControl("lblmrp") as Label).Text);
    wt = double.Parse(txtqty.Text);
    double pric = Convert.ToDouble(((Label)dr.FindControl("lblmrp")).Text);
    totlrp = mr * wt;
    txtbillamountcash.Text = Convert.ToString(totlrp);
    }
    }
    }
    }
    else
    {
    GridViewRow row = ddsales.FooterRow;
    ((Label)row.FindControl("Salary")).Text = Convert.ToString(foottotal);
    txtbillamountcash.Text = foottotal.ToString();
    }
    }



    i select the row using this code

    protected void ddsales_SelectedIndexChanged(object sender, EventArgs e)
    {
    foreach (GridViewRow row in ddsales.Rows)
    {
    if (row.RowIndex == ddsales.SelectedIndex)
    {
    row.BackColor = ColorTranslator.FromHtml("#A1DCF2");
    row.ToolTip = string.Empty;
    }
    else
    {
    row.BackColor = ColorTranslator.FromHtml("#FFFFFF");
    row.ToolTip = "Click to select this row.";
    }
    }
    }

    protected void ddsales_RowDataBound(object sender, GridViewRowEventArgs e)
    {
    if (e.Row.RowType == DataControlRowType.Header)
    {
    e.Row.Attributes["onclick"] = Page.ClientScript.GetPostBackClientHyperlink(ddsales, "Select$" + e.Row.RowIndex);
    e.Row.ToolTip = "Click to select this row.";

    GridViewRow row = new GridViewRow(0, -1, DataControlRowType.Header, DataControlRowState.Insert);
    TableCell th = new TableHeaderCell();
    th.Text = "Bramandam Family Shop<br/> DEvakottai";
    th.ColumnSpan = ddsales.Columns.Count;
    row.Cells.Add(th);
    ddsales.Controls[0].Controls.AddAt(0, row);
    }
    }
  • #762453
    Hi Selvi,

    I have reviewed your code and noticed you are selecting the row based on "ddlsales.selectedindex" not sure what it relates with the gridview row. It may be different with the selected index.

    You can put a radio button and based on the radio button selection, you can easily implement the row quantity.

    Also, overall codes are implemented in server side without any server usage. So, I would like to suggest to use all of these calculation by using Javascript or jQuery.

    Thanks,
    Damu

    Regards,
    V.M. Damodharan
    "Your talent will be worthless, when you have fear and tension."

  • #762454
    k thanks for your reply i try ur idea and tel

  • #762455
    Hi

    Can you share your error snapshot what error your facing check the index value correct or not can you use databound for your gridview row selected event

    Name : Dotnet Developer-2015
    Email Id :kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

  • #762459

    aqty.bmp

    Delete Attachment

  • #762460
    i try with radio button but same mistake

  • #762468
    Hi

    You can try this Code for selected row only updated purpose.




    <div id="div1" style="overflow:auto;height:150px; width: 1039px;" Width="108px">
    <asp:GridView ID="ddsales" runat="server" Width="707px" AutoGenerateColumns="false" onrowdatabound="ddsales_RowDataBound" onselectedindexchanged="ddsales_SelectedIndexChanged" onrowcommand="ddsales_RowCommand" ShowFooter="True" onrowdeleting="ddsales_RowDeleting" onselectedindexchanging="ddsales_SelectedIndexChanging" onprerender="ddsales_PreRender" onrowcreated="ddsales_RowCreated">
    <Columns>

    <asp:TemplateField>
    <ItemTemplate>
    <asp:RadioButton ID="RadioButton1" runat="server" AutoPostBack="true" OnCheckedChanged="RadioButton1_CheckedChanged" />
    <asp:HiddenField ID="HiddenField1" runat="server"
    Value = '<%#Eval("ID")%>' />
    </ItemTemplate>
    </asp:TemplateField>






    <asp:TemplateField HeaderText="Sectionname" ControlStyle-Width="120px"><ItemTemplate><asp:Label ID="lblsectn" runat="server" Text="<%#bind('sectionname') %>"></asp:Label> </ItemTemplate><ItemStyle Width="120px" VerticalAlign="Bottom" /><ControlStyle Width="120px" /> </asp:TemplateField>

    <asp:TemplateField HeaderText="Product Name" ControlStyle-Width="120px"><ItemTemplate><asp:Label ID="lblproductname" runat="server" Text="<%#bind('productname') %>"></asp:Label></ItemTemplate><ItemStyle Width="120px" VerticalAlign="Bottom" /><ControlStyle Width="120px" /></asp:TemplateField>

    <asp:TemplateField HeaderText="Lotno" ControlStyle-Width="120px">
    <ItemTemplate><asp:Label ID="lbllotno" runat="server" Text="<%#bind('lotno') %>"></asp:Label></ItemTemplate>
    <ItemStyle Width="120px" VerticalAlign="Bottom" /><ControlStyle Width="120px" /></asp:TemplateField>
    <asp:TemplateField HeaderText="Qty" ControlStyle-Width="60px">
    <ItemTemplate><asp:Label ID="lqtyyytno" runat="server" Text="<%#bind('qty') %>"></asp:Label></ItemTemplate>
    <ItemStyle Width="60px" VerticalAlign="Bottom" /><ControlStyle Width="60px" /></asp:TemplateField>

    <asp:TemplateField HeaderText="MRP" ControlStyle-Width="60px">
    <ItemTemplate><asp:Label ID="lblmrp" runat="server" Text="<%#bind('mrp') %>"></asp:Label></ItemTemplate>

    <FooterTemplate><asp:Label ID="Salary" runat="server" Visible="false" /></FooterTemplate>
    <ItemStyle Width="120px" VerticalAlign="Bottom" /><ControlStyle Width="120px" /></asp:TemplateField>
    <asp:TemplateField HeaderText="SupplierName" ControlStyle-Width="120px"><ItemTemplate><asp:Label ID="lblsupliername" runat="server" Text="<%#bind('supplierename') %>"></asp:Label></ItemTemplate><ItemStyle Width="120px" VerticalAlign="Bottom" /><ControlStyle Width="120px" /></asp:TemplateField>
    <asp:TemplateField HeaderText="Sizee" ControlStyle-Width="40px">
    <ItemTemplate><asp:Label ID="lblsizee" runat="server" Text="<%#bind('sizee') %>"></asp:Label></ItemTemplate>
    <ItemStyle Width="40px" VerticalAlign="Bottom" /><ControlStyle Width="40px" /></asp:TemplateField>
    <asp:TemplateField HeaderText="Delete User Details">
    <ItemTemplate>
    <asp:LinkButton ID="lbRemove" runat="server" CommandArgument='<%#bind("lotno") %>' CommandName="Delete" Text="Remove" ></asp:LinkButton></ItemTemplate>
    <ItemStyle Width="160px" VerticalAlign="Bottom" /><ControlStyle Width="160px" /></asp:TemplateField></Columns></asp:GridView></div>




    Server Side C#


    protected void RadioButton1_CheckedChanged(object sender, EventArgs e)
    {
    for (int i = 0; i < ddsales.Rows.Count; i++)
    {
    RadioButton rb = (RadioButton)ddsales.Rows[i].Cells[0].FindControl("RadioButton1");
    if (rb.Checked==true)
    {
    Label lqtyyytno = (Label)ddsales.Rows[i].Cells[1].FindControl("lqtyyytno");
    lqtyyytno.Text = txtqty.Text;
    }

    }

    }


    I have attached snapshot given below.

    Name : Dotnet Developer-2015
    Email Id :kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

    Delete Attachment

  • #762470
    Hi

    You can modified your table structure this added one column for id primary key then you can update delete easily.



    SET ANSI_NULLS ON
    GO

    SET QUOTED_IDENTIFIER ON
    GO

    SET ANSI_PADDING ON
    GO

    CREATE TABLE [dbo].[purchasedummy](
    [sectionname] [varchar](40) NULL,
    [lotno] [int] NULL,
    [Productname] [varchar](40) NULL,
    [mrp] [decimal](18, 2) NULL,
    [supplierename] [varchar](40) NULL,
    [sizee] [varchar](40) NULL,
    [qty] [int] NULL,
    [id] [int] IDENTITY(1,1) NOT NULL,
    PRIMARY KEY CLUSTERED
    (
    [id] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    ) ON [PRIMARY]

    GO

    SET ANSI_PADDING OFF
    GO


    Name : Dotnet Developer-2015
    Email Id :kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

  • #762481
    USE [bramandam]
    GO
    /****** Object: Table [dbo].[salcal] Script Date: 09/23/2015 14:38:59 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    SET ANSI_PADDING ON
    GO
    CREATE TABLE [dbo].[salcal](
    [id] [int] NULL,
    [salary] [float] NULL,
    [advance] [float] NULL,
    [remaining] [float] NULL,
    [extra] [float] NULL,
    [date] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
    [currentbalance] [float] NULL,
    [section] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
    [salcaa] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
    [name] [varchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
    [Totaladvance] [float] NULL,
    [bdate] [datetime] NULL,
    [idd] [int] IDENTITY(1,1) NOT NULL
    ) ON [PRIMARY]

    GO
    SET ANSI_PADDING OFF

  • #762483
    Hi

    In your previous table i have update corresponding row qty updated so which column need to change you mention above table structure.

    Can you explain more.

    Name : Dotnet Developer-2015
    Email Id :kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

  • #762524
    still all rows are affected

  • #762534

    Hi

    look this code below i mention here


    RadioButton rb = (RadioButton)ddsales.Rows[i].Cells[0].FindControl("RadioButton1");
    if (rb.Checked==true)
    {
    Label lqtyyytno = (Label)ddsales.Rows[i].Cells[1].FindControl("lqtyyytno");
    lqtyyytno.Text = txtqty.Text;
    }


    here when we check the record corresponding checked data only affected because i check checked is true so


    In gridview remove this line

    <asp:HiddenField ID="HiddenField1" runat="server"
    Value = '<%#Eval("ID")%>' />

    no need id column because we dont use id in server side so

    try and let me know.


    Name : Dotnet Developer-2015
    Email Id :kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.


Sign In to post your comments