Home
|
Tutorial
|
Articles
|
Forum
|
Interview Question
|
Code Snippets
|
News
|
Fun Zone
|
Poll
|
Web Links
|
Certification
|
Search
Welcome :
Guest
Sign In
Register
Win Surprise Gifts!!!
Congratulations!!!
Top 5 Contributors of the Month
Syed Shakeer Hussain
laptop charles
Sunil Yadav
Abhisek Panda
Dhananjay Kumar
Home
>>
Forum
>>
Windows Application
>>
Post New Question
Subscribe to Forum
datagridview --- only 3(10) colums have to be bounded
Posted By :
Jayakumar
Posted Date :
05/03/2010
Points :
2
Category :
Windows Application
hi,
i am working @ windows application with c#.
i have to select 10 columns(single row with 10 columns) from table A.
first--i have to bind only three columns with datagridview1..
second--i have to show out ten columns in separate labels on datagridview1 content click event.
autogenerate column is not working.
how it can be done..
Responses
Author:
Syed Shakeer Hussain
Company URL:
http://www.dotnetspark.com
Posted Date: 06/03/2010 Points: 5
Hi jayakumar,
1)Binding only three column to the datagridview
SqlDataAdapter da=new SqlDataAdapter("select id,name,deptname from A",conn);
DataSet ds=new DataSet();
da.Fill(ds,"A);
DataGridView1.DataSource=ds.Tables["A];
OutPut of your DataGidview
id name deptname
-----------------------
1 AAA dAAA
2 BBB dBBB
3 CCC dCCC
2)bleow code is when you click on the content of you DataGrid it show the corresponding row Values
->Double click the DataGridView and write the below code
Private void dataGridView1_CellContentClick_1(objectsender,DataGridViewCellEventArgs e)
{
i = dataGridView1.SelectedCells[0].RowIndex;
int id= dataGridView1.Rows[i].Cells[0].Value;
SqlCommand cmd=new SqlCommand("select col1,col2,col3,col4,col5,........,col9,col10 where id="+id+"",conn);
SlqDataReader dr=cmd.ExecuteReader();
if(dr.Read())
{
lable11.Text=dr["col1].ToString();
label2.Text=dr["col2].ToString();
:
:
:
:
lable19.Text=dr["col9].ToString();
label10.Text=dr["col10].ToString();
}
else
{
label1.Text="No Records Found";
}
}
Note:In above Code or Program column 'id' have to use to get the values.
Make it as ANSWER if it HELPS you
Author:
Jayakumar
Company URL:
http://www.dotnetspark.com
Posted Date: 07/03/2010 Points: 5
hi
i am getting object ref=null error on dataGridView1_CellContentClick event.
label9.Text = dataGridView1.Rows[i].Cells[1].Value.ToString();
label10.Text = dataGridView1.Rows[i].Cells[2].Value.ToString();
label11.Text = dataGridView1.Rows[i].Cells[3].Value.ToString();
label12.Text = dataGridView1.Rows[i].Cells[4].Value.ToString();
label13.Text = dataGridView1.Rows[i].Cells[5].Value.ToString();
label14.Text = dataGridView1.Rows[i].Cells[6].Value.ToString();
label15.Text = dataGridView1.Rows[i].Cells[7].Value.ToString();
label16.Text = dataGridView1.Rows[i].Cells[8].Value.ToString();
label19.Text = dataGridView1.Rows[i].Cells[9].Value.ToString();
label20.Text = dataGridView1.Rows[i].Cells[10].Value.ToString();
textBox1.Text = dataGridView1.Rows[i].Cells[11].Value.ToString();
since i have make visible false for 7 column and binded data with dgv.
Post Reply
You must
Sign In
To post reply
Related Questions Related Questions
Search value in DataGridView in C#.NET windows app
Urgent datagridview edit updated rows C#.NET
Button control into DataGridView in C#.NET Windows App
DateTimePicker in DataGridView in C#.NET windows app
DataGridView Eventhandler C#.NET win app
Latest Forum Questions From The Same Category
save a directury structure(parent folder and child folder relation) in a hash table.
display 2 node of the tree
Close others forms in windows application
how to make crystal report customize in visual studio 2008
how to get alternate rows color in datagridview in c#.net code windows app
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more
Here
Quick Links For Forum Categories:
ASP.Net
Windows Application
.NET Framework
C#
VB.Net
ADO.Net
Sql Server
SharePoint
OOPs
Silverlight
IIS
JQuery
JavaScript/VBScript
Biztalk
WPF
Patten/Practices
WCF
Others
www.DotNetSpark.com
UnAnswered
All
Hall of Fame
Twitter
Terms of Service
Privacy Policy
Contact Us
Archives
Tell A Friend