Click here to Skip to main content
16,005,682 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
how to retrieve table name from gridview, from which the rows are displaying?

I have a gridview from different tables of database.when i click on the cell, messagebox should display the tablename, from which the row is displaying...?
Posted
Comments
Herman<T>.Instance 13-Aug-11 13:52pm    
How do you do your request at the database? Via queries or stored procedures or linq?
Abhinav S 13-Aug-11 14:02pm    
Good hint to OP. Should give him the answer as well.

If your DataSource is really a Table, you can get its name like
((DataTable)dgrid.DataSource).TableName

Note that the DataSource doesn't have to be a table, it can be a DataSet for example (in this case dgrid.DataMember should give you the table name), or any other supported object... so wrap your test into a try-catch block.
 
Share this answer
 
The class inheritence hierarchy is something like this

DataSet->Table[i]->Rows
 
Share this answer
 

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