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

    Discount for a particular row and show it in gridview all rows are affected

    if i put discount all rows are affected. i need it for a single row discount.
  • #762485
    Hi

    In your previous post discount did not comes in your grid so i assuming some work and post for your issue.

    You can follow this steps

    Step1:

    Add one Discount Column in your Table



    SELECT * FROM [TestNew].[dbo].[purchasedummy]

    Alter Table [purchasedummy] add Discount decimal(18,2)

    Update [purchasedummy] set discount=0



    Step2:

    Add the Discount column in your Gridview



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



    Step3

    In server side C# code



    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");
    Label lblDiscount = (Label)ddsales.Rows[i].Cells[1].FindControl("lblDiscount");
    lqtyyytno.Text = txtqty.Text;
    lblDiscount.Text = txtdispr.Text;
    }

    }

    }



    In your txtdispr_TextChanged check and change control name for your requirement in your gridview

    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

  • #762486

    Hi

    You can try this code for Discount Update Default calculation I assume and post expect your output.



    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");
    Label lblDiscount = (Label)ddsales.Rows[i].Cells[1].FindControl("lblDiscount");
    Label lblmrp = (Label)ddsales.Rows[i].Cells[1].FindControl("lblmrp");
    decimal totdis = Convert.ToDecimal(lblmrp.Text) * Convert.ToDecimal(txtdispr.Text) / 100;
    decimal Totaldisc = Convert.ToDecimal(lblmrp.Text) - totdis;
    lqtyyytno.Text = txtqty.Text;
    lblDiscount.Text = Totaldisc.ToString(); //txtdispr.Text;
    }

    }

    }



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

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

  • #762508
    Hi selvi,

    Is this well formed question.?

    Where you add discount.? where you saved those details.?

    Are you saved in temporary tables (datatable..), if Yes, then check the datasource of that, whether it is reflected in all rows or current row of the value. If it's reflected in all the rows then before insert the value check the condition it should update only selected record, to overcome the above issue.

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/

  • #762519
    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");
    Label lblDiscount = (Label)ddsales.Rows[i].Cells[1].FindControl("indisshow");
    Label lblmrp = (Label)ddsales.Rows[i].Cells[1].FindControl("lblmrp");
    decimal totdis = Convert.ToDecimal(lblmrp.Text) * Convert.ToDecimal(txtdispr.Text) / 100;
    decimal Totaldisc = Convert.ToDecimal(lblmrp.Text) - totdis;
    ((Label)ddsales.Rows[i].Cells[1].FindControl("lblmrp")).Text = Convert.ToString(Totaldisc);
    }
    ((RadioButton)ddsales.Rows[i].Cells[0].FindControl("RadioButton1")).Checked = false;
    }
    txtdispr.Text = "";

    just modify ur code mr.kumar..

  • #762520
    in a gridview i show the following data
    product qty mrp

    1 1 10

    c 1 50

    like this i have discount field in outside the grid if i put discount for the product c disocunt is 10% i need to show the 50-5(thiss is discount for 50) need to show the 45 amount in the grid


Sign In to post your comments