Hi everyone...
I'm developing an application in asp.net with C#.net and Sqlserver as backend connecting to a local server.In one of the web forms the requirement is such that when I select an item from the Dropdown list, data must get populated into a gridview by running a query in which in "where" condition giving the item selected from the ddl.The problem is when I select an item from the ddl the grid view is displaying the data correctly.Again when I'm selecting any other item then the record(s) regarding that item are displayed twice (side by side in the gridview)and everytime this is getting multiplied as many items are selected.
Please help me out as i'm really fed up with this its..very urgent..Plzzzz provide the code for binding the data to the gridview at runtime.
This is the code I've written plzzzzz tell me if there are any errors...
[code=cpp]
cn.Open();
cmd = new SqlCommand("Spr oc_GetDataProdW ise", cn);
SqlDataAdapter da = new SqlDataAdapter( );
cmd.CommandType = CommandType.Sto redProcedure;
cmd.Parameters. Add("@ProductNa me", SqlDbType.VarCh ar, 100).Value = productname;
DataSet ds = new DataSet();
da.SelectComman d = cmd;
da.Fill(ds, "Sproc_GetDataP rodWise");
if (ds.Tables.Coun t > 0)
{
//Building all the columns in the table.
foreach (DataColumn dc in ds.Tables[0].Columns)
{
BoundField bField = new BoundField();
//Initalize the DataField value.
bField.DataFiel d = dc.ColumnName;
//Initialize the HeaderText field value.
bField.HeaderTe xt = dc.ColumnName;
//Add the newly created bound field to the GridView.
GV_prodwiselist .Columns.Add(bF ield);
}
}
//GV_customerwise list.DataSource = ds.Tables["Sproc_GetDataC ustWise"].DefaultView;
GV_prodwiselist .DataSourceID = null;
GV_prodwiselist .AllowSorting = false;
GV_prodwiselist .DataSource = ds;
GV_prodwiselist .DataBind();
//lbl_customernam e.Text = ds.Tables[0].Rows.Count.ToS tring();
cn.Close();
[/code]
Thanks in advance
siri
I'm developing an application in asp.net with C#.net and Sqlserver as backend connecting to a local server.In one of the web forms the requirement is such that when I select an item from the Dropdown list, data must get populated into a gridview by running a query in which in "where" condition giving the item selected from the ddl.The problem is when I select an item from the ddl the grid view is displaying the data correctly.Again when I'm selecting any other item then the record(s) regarding that item are displayed twice (side by side in the gridview)and everytime this is getting multiplied as many items are selected.
Please help me out as i'm really fed up with this its..very urgent..Plzzzz provide the code for binding the data to the gridview at runtime.
This is the code I've written plzzzzz tell me if there are any errors...
[code=cpp]
cn.Open();
cmd = new SqlCommand("Spr oc_GetDataProdW ise", cn);
SqlDataAdapter da = new SqlDataAdapter( );
cmd.CommandType = CommandType.Sto redProcedure;
cmd.Parameters. Add("@ProductNa me", SqlDbType.VarCh ar, 100).Value = productname;
DataSet ds = new DataSet();
da.SelectComman d = cmd;
da.Fill(ds, "Sproc_GetDataP rodWise");
if (ds.Tables.Coun t > 0)
{
//Building all the columns in the table.
foreach (DataColumn dc in ds.Tables[0].Columns)
{
BoundField bField = new BoundField();
//Initalize the DataField value.
bField.DataFiel d = dc.ColumnName;
//Initialize the HeaderText field value.
bField.HeaderTe xt = dc.ColumnName;
//Add the newly created bound field to the GridView.
GV_prodwiselist .Columns.Add(bF ield);
}
}
//GV_customerwise list.DataSource = ds.Tables["Sproc_GetDataC ustWise"].DefaultView;
GV_prodwiselist .DataSourceID = null;
GV_prodwiselist .AllowSorting = false;
GV_prodwiselist .DataSource = ds;
GV_prodwiselist .DataBind();
//lbl_customernam e.Text = ds.Tables[0].Rows.Count.ToS tring();
cn.Close();
[/code]
Thanks in advance
siri
Comment