Datagrid
-
Hi guys, I have a datagrid which is dynamically created using server-side code. The columns and rows, and just about any of it are all created depending on the users search criteria.What I want to know is that in the OnItem_DataBound event, a user can do this: e.item.cells(4).Text = "SomeText" BUT, when the datagrid is dynamic.. cell number 4 will be different each time. I want to be able to find and target cells by "FindingByText" or something rather than cells(4). Cells(4) is very static. I hope that made sense. Please ask me any questions to elaborate on my point. Thank you!
-
Hi guys, I have a datagrid which is dynamically created using server-side code. The columns and rows, and just about any of it are all created depending on the users search criteria.What I want to know is that in the OnItem_DataBound event, a user can do this: e.item.cells(4).Text = "SomeText" BUT, when the datagrid is dynamic.. cell number 4 will be different each time. I want to be able to find and target cells by "FindingByText" or something rather than cells(4). Cells(4) is very static. I hope that made sense. Please ask me any questions to elaborate on my point. Thank you!
I don't get how this is supposed to work, or what you're doing with this. You're trying to fill in Text in a specific column without knowing which column you're filling in? About the only thing you can do to find theproper column is get the names of the column from the DataTable and search through those to get the column number.
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007 -
I don't get how this is supposed to work, or what you're doing with this. You're trying to fill in Text in a specific column without knowing which column you're filling in? About the only thing you can do to find theproper column is get the names of the column from the DataTable and search through those to get the column number.
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007Thanks for the reply. I was kinda hoping there is a syntatic way of changing the text of a column on the datagrid when it is displayed. One method is to use the OnItem_DataBound event and use e.item.cells(0).text = "SomeText" BUT.. the problem is, the column's text that I am wanting to manipulate is not always present when that datagrid is produced. In addition, its position is not known. Therefore if I use e.item.cells(0).Text = "SomeText", it will not work all the time because the column's position changes depending on what columns the user chooses have as part of this datagrid. One way I was thinking of was to use a "for" loop and say something like this:
**Dim** i as Int **For Each** e.item.cells(i).blabla .. **If** the column name is "ColumnName" Then **Select** e.item.cells(i).Text **Case** x e.item.cells(i).Text = "Bla" **Case** y e.item.cells(i).Text = "BlaBla" **Case** z e.item.cells(i).Text = "BlaBlaBla" **End Select End If Next**
Another way of doing this is to change what the database returns. You see, I am supposed to be "Saving" Reports, and those reports are saved in the database as views, and retrieved whenever needed by binding data from the relevant views. This creates a problem because the view is not always present. I will therefore have to produce code to create the views in such a way that It understands what to do if the column in question is ever selected. Both are doable I think.. but which is easier? or better? hmm...:confused: -
Thanks for the reply. I was kinda hoping there is a syntatic way of changing the text of a column on the datagrid when it is displayed. One method is to use the OnItem_DataBound event and use e.item.cells(0).text = "SomeText" BUT.. the problem is, the column's text that I am wanting to manipulate is not always present when that datagrid is produced. In addition, its position is not known. Therefore if I use e.item.cells(0).Text = "SomeText", it will not work all the time because the column's position changes depending on what columns the user chooses have as part of this datagrid. One way I was thinking of was to use a "for" loop and say something like this:
**Dim** i as Int **For Each** e.item.cells(i).blabla .. **If** the column name is "ColumnName" Then **Select** e.item.cells(i).Text **Case** x e.item.cells(i).Text = "Bla" **Case** y e.item.cells(i).Text = "BlaBla" **Case** z e.item.cells(i).Text = "BlaBlaBla" **End Select End If Next**
Another way of doing this is to change what the database returns. You see, I am supposed to be "Saving" Reports, and those reports are saved in the database as views, and retrieved whenever needed by binding data from the relevant views. This creates a problem because the view is not always present. I will therefore have to produce code to create the views in such a way that It understands what to do if the column in question is ever selected. Both are doable I think.. but which is easier? or better? hmm...:confused:What are you doing with this column?? It looks like you're returning a column, but when you go to display it in the datagrid you're replacing what would be shown with some other text entirely, or possibly reformatting the data in that column, correct?
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007 -
What are you doing with this column?? It looks like you're returning a column, but when you go to display it in the datagrid you're replacing what would be shown with some other text entirely, or possibly reformatting the data in that column, correct?
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007lol .. sorry for the confusion. You are correct. Here are the steps that are involved with the creation of this datagrid: 1 - User Selects the column names from the webpage 2 - User clicks on "Run" 3 - The Application runs a SELECT query involing ONLY the selected Columns. 4 - User Enters a name into a Textbox and clicks on save. 5 - The application runs a "Create View" query to the database. This "Create View" query will have ONLY the columns selected. 6 - You return to the main report page. There is a dropdown list which is populated by data in a table which stores records about 'Saved' Reports(which the user has stored just now) 7 - The user then selects the report name which he just saved from the dropdown. 8 - The name from the dropdown refers to the view which was created. A - All the views are dynamically created. B - The same DataGrid is being used to display any of those views. C - There is ONE column that a User may or may not select. D - If he selects it, I want the contents of that column to be manipulated; Else forget about it. Normally for a static set of data being retrieved, I use "e.item.cells().Text = something" for manipulation, but that syntax refers to a column which is in a fixed position and which is always there no matter what. BUT I am looking for some syntax which will target that particular column which may or may not be returned depending on whether the user has selected it. I am very sorry for the confusion. If this does not make sense to you, don't worry about it any more. It may be too confusing to solve by communicating online. Thanks a lot for your replies.
-
lol .. sorry for the confusion. You are correct. Here are the steps that are involved with the creation of this datagrid: 1 - User Selects the column names from the webpage 2 - User clicks on "Run" 3 - The Application runs a SELECT query involing ONLY the selected Columns. 4 - User Enters a name into a Textbox and clicks on save. 5 - The application runs a "Create View" query to the database. This "Create View" query will have ONLY the columns selected. 6 - You return to the main report page. There is a dropdown list which is populated by data in a table which stores records about 'Saved' Reports(which the user has stored just now) 7 - The user then selects the report name which he just saved from the dropdown. 8 - The name from the dropdown refers to the view which was created. A - All the views are dynamically created. B - The same DataGrid is being used to display any of those views. C - There is ONE column that a User may or may not select. D - If he selects it, I want the contents of that column to be manipulated; Else forget about it. Normally for a static set of data being retrieved, I use "e.item.cells().Text = something" for manipulation, but that syntax refers to a column which is in a fixed position and which is always there no matter what. BUT I am looking for some syntax which will target that particular column which may or may not be returned depending on whether the user has selected it. I am very sorry for the confusion. If this does not make sense to you, don't worry about it any more. It may be too confusing to solve by communicating online. Thanks a lot for your replies.
I think I got it now. I think all you have to do is scan the column headers (For I = 0 to MaxColumns) for the name you're looking for, then just save the index of that column for use in your Cells reference.
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007 -
I think I got it now. I think all you have to do is scan the column headers (For I = 0 to MaxColumns) for the name you're looking for, then just save the index of that column for use in your Cells reference.
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007