Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 ASP.NET
 Binding Datagrid to DataReader dynamically

Author  Topic 

chiragkhabaria
Master Smack Fu Yak Hacker

1907 Posts

Posted - 2007-05-09 : 12:24:23
Hello All,

Just trying my luck over here, its possible to do the following..

I want to bind the Datagrid dynamically to the Datareader in one my Webpages. I did search through web but didnt find any relevant help or the information on binding Datareader dynamically.

Yes there are plenty of link for binding Datatable or Dataview to the Datagrid, but no information for Datareader.



Chirag

http://chirikworld.blogspot.com/

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-05-09 : 12:31:50
Just found this on google:

[url]http://www.easerve.com/developer/tutorials/asp-net-tutorials-datareader-datagrid-vbnet.aspx[/url]

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-05-09 : 12:35:27
Chirag,

I am seriously confused..the topic says you want to bind DataView to DataGrid but post says you want DataReader to be bound with DataGrid !

What exactly you want?

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2007-05-09 : 13:41:23
just set the datasource to the datareader, call DataBind(), and that should be all you need to do.

- Jeff
http://weblogs.sqlteam.com/JeffS
Go to Top of Page

chiragkhabaria
Master Smack Fu Yak Hacker

1907 Posts

Posted - 2007-05-09 : 14:35:00
quote:
Originally posted by harsh_athalye

Chirag,

I am seriously confused..the topic says you want to bind DataView to DataGrid but post says you want DataReader to be bound with DataGrid !

What exactly you want?

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"



Aha Well.. its the Datareader.. and i corrected the topic name..!!

Thanks for the Link.. i will dig into and will get back to you...

aha.. Jeff.. i tried the same thing. but it unfortunately it wasnt working for me..

Chirag

http://chirikworld.blogspot.com/
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2007-05-09 : 15:06:46
>> aha.. Jeff.. i tried the same thing. but it unfortunately it wasnt working for me..

This might sound like a crazy idea, but perhaps if you explained why it isn't "working" with some actual details, we might be able to help you better?



- Jeff
http://weblogs.sqlteam.com/JeffS
Go to Top of Page

chiragkhabaria
Master Smack Fu Yak Hacker

1907 Posts

Posted - 2007-05-09 : 15:32:26
Aha.. I dont know i would have been doing the most craziest thing... but well. it worked after doing some alternation in the code..

Here is my code.. its just an dummpy code on the dumpy project..


void BindGrid()
{
string strError = "";
SqlDataReader myreader = null;
SQLClass.Connect_SQLDataReader(ref myreader, "select * From Area", ref strError, false);
dg.DataSource = myreader;
dg.DataBind();
}



Is there any way i can modify the column one to be an hyper link column dynamically..??? or may i am asking to much ??

The query which is passed to the Datareader will be changed at run time based on some clicks..

Thanks..

Chirag

http://chirikworld.blogspot.com/
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2007-05-09 : 15:42:22
I am not sure what you are asking ... what do you mean by making it a "hyperlink column dynamically?" Do you mean sometimes it is a hyperlink, sometimes not? Again, some examples and more specifics will be helpful... We could make some wild guesses, but why don't you just tell us what you are trying to do.

- Jeff
http://weblogs.sqlteam.com/JeffS
Go to Top of Page

chiragkhabaria
Master Smack Fu Yak Hacker

1907 Posts

Posted - 2007-05-09 : 15:54:42
oks.. Sorry for not being Specific..

Here is the things what I am trying to achieve.

1) The Grid should be dynamically filled with the detail, which i guess is achieved.

2) Some of the columns in the gird are required to be Hyper link to some pop up. The pop up will be opened, with some query string to it, with that help of that query string string some processing will be done in this page.

Now since this grid is filled dynamically I don't know how should place or where should i place HyperLinkColumn object, so that first column or any other columns in the grid appears as the Hyper link..

Well I hope I am able to understand my problem..!!

Chirag

http://chirikworld.blogspot.com/
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2007-05-09 : 16:00:30
Just use template columns, and in the templates you can dynamically hide/show/edit hyperlink controls or other controls depending on your data. use the ItemDataBound event if necessary to process each one as the rows are databound.

- Jeff
http://weblogs.sqlteam.com/JeffS
Go to Top of Page

chiragkhabaria
Master Smack Fu Yak Hacker

1907 Posts

Posted - 2007-05-09 : 16:17:48
Any Sample link for the same?? I did some google but didnt found anything working in my way..:(

Chirag

http://chirikworld.blogspot.com/
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2007-05-09 : 16:31:27
http://msdn.microsoft.com/msdnmag/issues/01/06/cutting/
http://aspnet.4guysfromrolla.com/articles/061002-1.aspx
http://www.devx.com/vb2themax/Tip/18857

hopefully that will get you started.

- Jeff
http://weblogs.sqlteam.com/JeffS
Go to Top of Page

chiragkhabaria
Master Smack Fu Yak Hacker

1907 Posts

Posted - 2007-05-10 : 03:50:12
Thanks for the link.. that was very help ful..

but my last question is that..

I need to develop the page where, the information will be displayed in the Tree, and on clicking the nodes of the Tree the value has to populated in the grid on the basis of the Different tables and records in each table has around 20k-100k rows and which i suspecting to grow around 200k in a years time. so here the performance is also an issue.
and in most of the cases the columns are required to be hyperlinked to some pop up page with some query string and on basis of this query string there will be some processing done.

I was thinking to have one grid,setting to the different datasource to the different table.. and all at the run time.

Also the Tree will be having around 2 Levels of hirarchy and it will go upto 15-20 nodes.

Can you tell me what is the best way to handle this and even some link will be greatly

Thanks for your kind help

Chirag

http://chirikworld.blogspot.com/
Go to Top of Page
   

- Advertisement -