Click here to Skip to main content
15,896,111 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have one variable in which column headers are defined as string.Now I wqant to assign this string variable to datagridview...How to do this?Please help me...Thanx in advance..
Posted
Comments
Sergey Alexandrovich Kryukov 3-Mar-13 23:24pm    
What did you try? First, read the help page on DataGridView and try to do what you want. If you face some problems, ask your questions.
—SA
Rachna0309 3-Mar-13 23:40pm    
Actually I converted my project from vb6 to vb.net 2005..And I am getting error on line :
"MSFGrid1.FormatString = FStr (FStr is string variable)"

1 solution

Hi,

The question aint very clear.
You can store your variables in a table and on Page_Load() event of the asp.net page , you cud assign it to the gridview.

Data access layer, you cud do something like:
C#
public DataTable Grid()
{
    SqlDataAdapter da1 = new SqlDataAdapter("select * from Sample.dbo.tblName", xconn);
    DataTable ds = new DataTable();
    da1.Fill(ds);
    return ds;
}


And in the aspx.cs page, you cud do somethinmg like:

C#
protected void Page_Load(object sender, EventArgs e)
{
    DAL obj2 = new DAL();
    DataTable dtnew2 = obj2.Grid();
    GridView1.DataSource = dtnew2;
    GridView1.DataBind();


}


Now you will have to think whether how will you store your variables, as in a table or do you wana take the values of the variables via a form from the user, in the latter case, you can call a stored procedure and stuffs. There are numerous methods, implementation depends upon scenarios and needs.

Hope it helps.
Happy coding..

regrds
anurag
 
Share this answer
 
Comments
Rachna0309 3-Mar-13 23:39pm    
This is a desktop application...Is this possible in vb.net too??
Anurag Sinha V 3-Mar-13 23:44pm    
Hi, It doesnt matter whether urs a web app or a win app...Page_Load() and stuffs are quite common and yes .NET framework supports VB.Net too, hence i guess you can implement the above via VB.net..:)...i wrote asp.net coz i thought you wud be havin some troubles in ur web app..nevamind...
hope it helps...

regards
anurag
Rachna0309 3-Mar-13 23:54pm    
Thanx....
Anurag Sinha V 4-Mar-13 0:36am    
np..happy coding.... :)

regards
anurag

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