Click here to Skip to main content
15,890,845 members
Home / Discussions / ASP.NET
   

ASP.NET

 
QuestionClearing Dropdownlist keeping the first index Pin
meeram39520-Jan-09 20:31
meeram39520-Jan-09 20:31 
AnswerRe: Clearing Dropdownlist keeping the first index Pin
Aman Bhullar20-Jan-09 21:03
Aman Bhullar20-Jan-09 21:03 
GeneralRe: Clearing Dropdownlist keeping the first index Pin
meeram39520-Jan-09 22:59
meeram39520-Jan-09 22:59 
GeneralRe: Clearing Dropdownlist keeping the first index Pin
meeram39520-Jan-09 23:00
meeram39520-Jan-09 23:00 
QuestionHow to get the selected value from the Repeater control? Pin
Karthick_gc20-Jan-09 20:14
Karthick_gc20-Jan-09 20:14 
AnswerRe: How to get the selected value from the Repeater control? Pin
N a v a n e e t h20-Jan-09 21:38
N a v a n e e t h20-Jan-09 21:38 
AnswerRe: How to get the selected value from the Repeater control? Pin
Abhishek Sur20-Jan-09 21:47
professionalAbhishek Sur20-Jan-09 21:47 
Questiondatagrid updation! Pin
RajpootRohan20-Jan-09 19:54
professionalRajpootRohan20-Jan-09 19:54 
Hi to all,

I am stucked in updating a datagrid when user changes the textbox value.
I am binding the datagrid through a datatable.
What I am doing is:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class Mycart : System.Web.UI.Page
{
    float total_Price = 0;
    int total_items = 0;
    int quanti;
    string pro_id;
    string desc;
    string id;
    int qty3;
    float unitprice;
    float cost;
    DataTable dt;
    DataTable dt2;
    DataGridItem dgItem;

    protected void Page_Load(object sender, EventArgs e)
    {
        if(!Page.IsPostBack)
        {
        if (Session["Cart"] == null)
        {
            dt = new DataTable();
            dt.Columns.Add("REF", typeof(string));
            dt.Columns.Add("Description", typeof(string));
            dt.Columns.Add("QTY", typeof(int));
            dt.Columns.Add("Price", typeof(float));
            dt.Columns.Add("Cost", typeof(float));
            get_data();
            Session["Cart"] = dt;
        }
        else
        {
            dt = (DataTable)Session["Cart"];
            get_data();
            Session["Cart"] = dt;
        }
        }
    }

    public void get_data()
    {
        pro_id = Request.QueryString["pr_id"];

        quanti = Convert.ToInt32(Request.QueryString["quant"]);

        if (pro_id != null)
        {
            SqlConnection con = new SqlConnection("Server=.; Database=eclsc; Trusted_Connection=yes");
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = con;
            cmd.CommandText = "select ICEMACHINES.product_id,ICEMACHINES.sh_desc,ICEMACHINES.price from ICEMACHINES where ICEMACHINES.product_id LIKE @product_id union select GLASSWARE.product_id,GLASSWARE.sh_desc,GLASSWARE.price from GLASSWARE where GLASSWARE.product_id LIKE @product_id ";
            cmd.Parameters.Add("@product_id", SqlDbType.NVarChar, 50).Value = pro_id;
            cmd.Connection.Open();
            SqlDataReader rdr = cmd.ExecuteReader();
            ArrayList arRole1 = new ArrayList();

            while (rdr.Read())
            {
                desc = (rdr["sh_desc"]).ToString();
                id = (rdr["product_id"]).ToString();
                unitprice = Convert.ToSingle((rdr["price"]));
                cost = unitprice * quanti;

            }
            cmd.Connection.Close();

            DataRow myrow = dt.NewRow();
            myrow["REF"] = id;
            myrow["Description"] = desc;
            myrow["QTY"] = quanti;
            myrow["Price"] = unitprice;
            myrow["Cost"] = cost;

            dt.Rows.Add(myrow);
            dt.AcceptChanges();
            Session["data"]= dt;
            DataGrid2.DataSource = dt;
            DataGrid2.DataBind();
            
        }
        else
        {
            int a = 1;
        }
        total_items = total_items + quanti;
        total_Price = total_Price + cost;
        Session["items"] = total_items;
        Session["value"] = total_Price;
    }

    protected void BtnUpdate_Click(object sender, EventArgs e)
    {
        dt = (DataTable)Session["Cart"];
        CheckBox chkSelected = new CheckBox();

        foreach (DataGridItem dgItem in DataGrid2.Items)
        {
            chkSelected = (CheckBox)dgItem.FindControl("chkSelection");

            if (chkSelected.Checked == true)
            {
                TextBox TxtQTY = (TextBox)dgItem.Cells[2].FindControl("TxtQTY");
                int Txt2 = Convert.ToInt32(TxtQTY.Text);

                Label lblProduct_Id = (Label)dgItem.Cells[0].FindControl("lblProduct_Id");
                string id2 = lblProduct_Id.Text;

                Label lblDescription = (Label)dgItem.Cells[1].FindControl("lblDescription");
                string desc2 = lblDescription.Text;

                Label lblPrice = (Label)dgItem.Cells[3].FindControl("lblPrice");
                float price2 = Convert.ToSingle(lblPrice.Text);

                Label lblCost = (Label)dgItem.Cells[3].FindControl("lblCost");
                float cost2 = Convert.ToSingle(lblCost.Text);

                float final_cost = price2 * Txt2;
                
                  DataRow myrow = dt.NewRow();
                  myrow["REF"] = id2;
                  myrow["Description"] = desc2;
                  myrow["QTY"] = Txt2;
                  myrow["Price"] = price2;
                  myrow["Cost"] = final_cost;

                  dt.Rows.Add(myrow);
                  dt.AcceptChanges();
                  Session["data"] = dt;
            }

        }
        DataGrid2.DataSource = dt;
        DataGrid2.DataBind();
    }

    protected void BtnSave_Click(object sender, EventArgs e)
    {

    }

    protected void BtnRetrieve_Click(object sender, EventArgs e)
    {

    }

    protected void BtnContinue_Click(object sender, EventArgs e)
    {
        Response.Redirect("Default2.aspx");
    }

    protected void BtnCheckout_Click(object sender, EventArgs e)
    {
        Response.Redirect("Checkout.aspx");
    }
}


Through this functionality I am able to update the datagrid but the problem is:
Suppose a user added two items in the datagrid.Then he checks one of the row to update.Then after updating it is showing three items.Instead of updating the same row it is adding the updated row below the previous two entries.

I am unable to get rid of this problem.
Thanks in advance.

cheers,
sneha

AnswerRe: datagrid updation! Pin
RajpootRohan20-Jan-09 21:08
professionalRajpootRohan20-Jan-09 21:08 
Questionhow to create a Menu with 3 level using Menu Control in ASP.net. Pin
Ravi Munde20-Jan-09 19:05
Ravi Munde20-Jan-09 19:05 
AnswerRe: how to create a Menu with 3 level using Menu Control in ASP.net. Pin
Karthick_gc20-Jan-09 19:48
Karthick_gc20-Jan-09 19:48 
QuestionUrl rewriting using c# Pin
Member 422892520-Jan-09 18:23
Member 422892520-Jan-09 18:23 
AnswerRe: Url rewriting using c# Pin
N a v a n e e t h20-Jan-09 18:40
N a v a n e e t h20-Jan-09 18:40 
QuestionGoogle Map API Integration in ASP .NET web page Pin
codingrocks20-Jan-09 18:20
codingrocks20-Jan-09 18:20 
AnswerRe: Google Map API Integration in ASP .NET web page Pin
N a v a n e e t h20-Jan-09 18:41
N a v a n e e t h20-Jan-09 18:41 
AnswerRe: Google Map API Integration in ASP .NET web page Pin
MacSpudster21-Jan-09 9:17
professionalMacSpudster21-Jan-09 9:17 
QuestionCall External Javascript File in aspx file Pin
anandhakrishnan20-Jan-09 17:21
anandhakrishnan20-Jan-09 17:21 
AnswerRe: Call External Javascript File in aspx file Pin
N a v a n e e t h20-Jan-09 17:30
N a v a n e e t h20-Jan-09 17:30 
AnswerRe: Call External Javascript File in aspx file Pin
Abhijit Jana20-Jan-09 17:32
professionalAbhijit Jana20-Jan-09 17:32 
QuestionCrystal Report 11 in VB ASP .NET Pin
saberbladez20-Jan-09 15:26
saberbladez20-Jan-09 15:26 
QuestionUser Control Embedded Classes Pin
MacSpudster20-Jan-09 12:06
professionalMacSpudster20-Jan-09 12:06 
QuestionPass Filepath between webforms Pin
Terick20-Jan-09 11:38
Terick20-Jan-09 11:38 
AnswerRe: Pass Filepath between webforms Pin
Christian Graus20-Jan-09 13:38
protectorChristian Graus20-Jan-09 13:38 
GeneralRe: Pass Filepath between webforms Pin
Terick21-Jan-09 3:33
Terick21-Jan-09 3:33 
GeneralRe: Pass Filepath between webforms Pin
Terick21-Jan-09 3:47
Terick21-Jan-09 3:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.