Results 1 to 3 of 3

Thread: [RESOLVED] [2005]Setting a datagrid index

  1. #1

    Thread Starter
    Fanatic Member space_monkey's Avatar
    Join Date
    Apr 2005
    Location
    神と歩くこと
    Posts
    573

    Resolved [RESOLVED] [2005]Setting a datagrid index

    Here's what i'm currently doing. To bind a dataset to a datagrid.

    VB Code:
    1. Dim myReports As New DATA_ACCESS
    2.             Dim dsReports As New DataSet
    3.             dsReports = myReports.GET_MY_REPORTS(Session("USER_NAME"))
    4.             ReportGrid.DataSource = dsReports
    5.             ReportGrid.DataBind()
    6.             myReports = Nothing
    7.             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:
    1. Dim dsDepts As New DataSet
    2.             dsDepts = depts.GET_DEPT_OPTS
    3.             ddDept.DataSource = dsDepts
    4.             ddDept.DataTextField = "DEPT_INFO_NAME"
    5.             ddDept.DataValueField = "DEPT_INFO_IDNM"
    6.             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)
    Using VB6 or VB.net 2008 with .net 3.5
    "Life... death... either way I'll be confined to a small cubicle!" - Hermes Conrad

  2. #2
    Fanatic Member
    Join Date
    May 2005
    Posts
    608

    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
    I do like the reward system. If you find that my post was useful, rate it.

  3. #3

    Thread Starter
    Fanatic Member space_monkey's Avatar
    Join Date
    Apr 2005
    Location
    神と歩くこと
    Posts
    573

    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:
    1. <asp:TemplateField>  
    2.                                     <HeaderTemplate>
    3.                                         Author
    4.                                     </HeaderTemplate>
    5.                                     <ItemTemplate>
    6.                                             <%#(Container.DataItem("Author"))%>
    7.                                     </ItemTemplate>
    8.                             </asp:TemplateField>

    It seems to be working quite nicely.

    Thanks
    Using VB6 or VB.net 2008 with .net 3.5
    "Life... death... either way I'll be confined to a small cubicle!" - Hermes Conrad

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width