[RESOLVED] [2005]Setting a datagrid index
Here's what i'm currently doing. To bind a dataset to a datagrid.
VB Code:
Dim myReports As New DATA_ACCESS
Dim dsReports As New DataSet
dsReports = myReports.GET_MY_REPORTS(Session("USER_NAME"))
ReportGrid.DataSource = dsReports
ReportGrid.DataBind()
myReports = Nothing
dsReports = Nothing
There's no problem there. Everything comes back fine. My question is, "how do i set the index/key for the grid?". Something like what i did with a drop down box.
VB Code:
Dim dsDepts As New DataSet
dsDepts = depts.GET_DEPT_OPTS
ddDept.DataSource = dsDepts
ddDept.DataTextField = "DEPT_INFO_NAME"
ddDept.DataValueField = "DEPT_INFO_IDNM"
ddDept.DataBind()
Here when an item is selected in the dropdown box i can see a behind the scenes value for it. I'd like to do the same thing with the datagrid. Basically have a column in my dataset that doesn't show in the datagrid but is recognized as the index for that row in the code behind. Or am i going about this the wrong way.
Thanks
Andy (ASP.NET noob)
Re: [2005]Setting a datagrid index
You can setup an entire column of Ids and make it visible="False" in the HTML part of the Datagrid, using templates. Only the code behind sees it.
HTH
HoraShadow
Re: [2005]Setting a datagrid index
Thanks for your reply. I was on this path already for a hypertext column i wanted; i just didn't realize that it extended to this.
here's what i ended up doing. I first had to turn off the AutoGeneratecolumns and then just provide a template for each of the columns that i wanted after that. For example
VB Code:
<asp:TemplateField>
<HeaderTemplate>
Author
</HeaderTemplate>
<ItemTemplate>
<%#(Container.DataItem("Author"))%>
</ItemTemplate>
</asp:TemplateField>
It seems to be working quite nicely.
Thanks