By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,857 Members | 1,768 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,857 IT Pros & Developers. It's quick & easy.

ComboBox in Datagridview in vb.net2005

mafaisal
100+
P: 142
Hello

I am Using vb.net2005
My Doubt is When i bind database to datagridview how to create combobox in that
my code is
StrSQL = "Select SlNo,Fname,Relation,Age,gender,Others From EmpDet a,EmpMast b Where a.Id = b.Id And b.Id = " & Val(TxtID.Text) & " "
Dap = New OleDb.OleDbDataAdapter(StrSQL, Con)
Dap.Fill(DstDet, "DstDet")
DGView.DataSource = DstDet
DGView.DataMember = "DstDet"

here the colum of gender coming in Combobox hw that is created...?
Jan 16 '08 #1
Share this Question
Share on Google+
2 Replies


dip_developer
Expert 100+
P: 648
Hello

I am Using vb.net2005
My Doubt is When i bind database to datagridview how to create combobox in that
my code is
StrSQL = "Select SlNo,Fname,Relation,Age,gender,Others From EmpDet a,EmpMast b Where a.Id = b.Id And b.Id = " & Val(TxtID.Text) & " "
Dap = New OleDb.OleDbDataAdapter(StrSQL, Con)
Dap.Fill(DstDet, "DstDet")
DGView.DataSource = DstDet
DGView.DataMember = "DstDet"

here the colum of gender coming in Combobox hw that is created...?
just create a dataset with another sql query which selects the gender....and set the datasource of the combo to that dataset...

see how....

Expand|Select|Wrap|Line Numbers
  1.  public DataSet PopulateDropDownList() 
  2. {
  3. SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["MyDatabase"].ConnectionString);
  4. SqlDataAdapter ad = new SqlDataAdapter("SELECT DISTINCT gender FROM EmpDet", myConnection);
  5. DataSet ds = new DataSet();
  6. ad.Fill(ds, "tblgender");
  7. return ds; 
  8. }
  9.  
Now let's see where we call this method...........
Expand|Select|Wrap|Line Numbers
  1.  
  2. <ItemTemplate>
  3. <asp:DropDownList ID="DropDownList1" runat="server" DataSource="<%# PopulateDropDownList() %>" 
  4. DataTextField="Gender" DataValueField = "GenderID">
  5. </asp:DropDownList>
  6. </ItemTemplate>
  7.  
  8.  
Jan 17 '08 #2

mafaisal
100+
P: 142
Hello

Thanx for reply
ok i under stand
My Prob is When we Bind dataset to datagridview i think all column as
datagridviewtextboxcolumn then hw to make datagridviewcomboboxcolumn in gendercolumn

Faisal

just create a dataset with another sql query which selects the gender....and set the datasource of the combo to that dataset...

see how....

Expand|Select|Wrap|Line Numbers
  1.  public DataSet PopulateDropDownList() 
  2. {
  3. SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["MyDatabase"].ConnectionString);
  4. SqlDataAdapter ad = new SqlDataAdapter("SELECT DISTINCT gender FROM EmpDet", myConnection);
  5. DataSet ds = new DataSet();
  6. ad.Fill(ds, "tblgender");
  7. return ds; 
  8. }
  9.  
Now let's see where we call this method...........
Expand|Select|Wrap|Line Numbers
  1.  
  2. <ItemTemplate>
  3. <asp:DropDownList ID="DropDownList1" runat="server" DataSource="<%# PopulateDropDownList() %>" 
  4. DataTextField="Gender" DataValueField = "GenderID">
  5. </asp:DropDownList>
  6. </ItemTemplate>
  7.  
  8.  
Jan 17 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.