Click here to Skip to main content
15,893,190 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
When i select a donumber from dropdown list selected donumber related information i have to display in Gridview & a Detail View in same page. below is my c# code for for Dropdown list and Gridview to display the data.

Please guide how to link?


protected void doddl_SelectedIndexChanged(object sender, EventArgs e)
    {
        
        
        detailviewFill();
        DetailsView1.DataBind();
        PrintGv.DataBind();
       
    }


 public void fillDropDownList()
    {
        string connectionString = ConfigurationManager.ConnectionStrings["InvoiceConnectionString"].ConnectionString;
        string selectSql = "SELECT DoNumber from ItemParent Where DoNumber = @DoNumber   ";
        SqlConnection conn = new SqlConnection(connectionString);
        SqlCommand cmd = new SqlCommand(selectSql, conn);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        da.Fill(ds);
        doddl.DataSource = ds;
        doddl.DataTextField = "DoNumber";
        doddl.DataValueField = "DoNumber";
        doddl.DataBind();
    }

   public void gridfill()
    {
        DataSet ds = new DataSet();
        string selectSql = "Select ItemParent.Notes,Items.Description, Items.ItemNo, Items.Qty FROM ItemParent INNER JOIN  Items ON ItemParent.DoNumber = Items.DoNumber";
        string connectionString = ConfigurationManager.ConnectionStrings["InvoiceConnectionString"].ConnectionString;
        SqlConnection conn = new SqlConnection(connectionString);
        SqlDataAdapter da = new SqlDataAdapter(selectSql, conn);
        da.Fill(ds, "Items");
        PrintGv.DataSource = ds.Tables["Items"];

    }


Thanks
Posted

Hi,

I give a solution to bind data on dropdown list ,grid view and details view using class file.
At first connect to data base though connection string then check connection and open the connection fill dataset then after bind the control data source to dataset.

i give here class file code:
for drop down list.

C#
public void FillDropDownList(string Str,  DropDownList Ddl)
    
    {
        if (CheckCon() == true)
        {
            DataSet Ds = new DataSet();
            ExecuteDataset(Str, ref Ds);
            Ddl.DataSource = Ds.Tables[0];
            Ddl.DataValueField = Ds.Tables[0].Columns[0].ColumnName;
            Ddl.DataTextField = Ds.Tables[0].Columns[1].ColumnName;
            Ddl.DataBind();
            ListItem Li = new ListItem();
            Li.Value = "0".ToString();
            Ddl.Items.Insert(0, Li);
        }
    }


for grid view:

C#
public void FillGridView(GridView Grd, string Str)
   {
       if (CheckCon() == true)
       {
           Ds = new DataSet();
           Da = new SqlDataAdapter(Str, Con);
           Da.Fill(Ds, "tab");
           Grd.DataSource = Ds.Tables["tab"];
           Grd.DataBind();

       }
   }



for details view:

C#
public void FillDetailsView(DetailsView DeViw, string Str)
    {
        if (CheckCon() == true)
        {
            Ds = new DataSet();
            Da = new SqlDataAdapter(Str, Con);
            Da.Fill(Ds, "tab");
            DeViw.DataSource = Ds.Tables["tab"];
            DeViw.DataBind();

        }
    }
 
Share this answer
 
v2
Comments
Lancy.net 1-Dec-11 3:08am    
hi thanks for your reply i have a doubt please
in one select statement we have to get all the values or
for grid view seperate and detail view seperate...
Lancy.net 1-Dec-11 3:19am    
i dont know my question is correct or not? what the code u have given is for DDlist,Gview,detailview individually ... what i want is when i select let say dgg0001 as donumber in dropdown list in detail view it should display customer name,address for donumber related ,GRid view ---- item details please advice
Member 8740531 21-Mar-12 6:43am    
After using gvn above codes i face an error "if (CheckCon() == true)" in this line. hw can i overcome

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900