[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 244
  • Last Modified:

ASP.net Datagrid - visible=false column not showing up when I iterate through each row

I have a datagrind set up as so.

<asp:datagrid id="dgList" OnDeleteCommand="dgList_Delete" runat="server" Width="464px" autogeneratecolumns="false">
<Columns>
    <asp:TemplateColumn HeaderText="Sequence">
             <ItemTemplate>
      <asp:DropDownList ID="Sequence" Runat="server" DataSource = '<%# Get_Schedule_Numbers() %>' SelectedIndex = '<%# DataBinder.Eval(Container, "DataItem.Sequence") - 1 %>'>
      </asp:DropDownList>
              </ItemTemplate>
     </asp:TemplateColumn>

(A few more inbetween)

     <asp:TemplateColumn  Visible = False>
      <ItemTemplate>
      <asp:TextBox Runat="server" ID="ID" text='<%# DataBinder.Eval(Container, "DataItem.ID") %>'>
      </asp:TextBox>
      </ItemTemplate>
      </asp:TemplateColumn>
</Columns>
</asp:datagrid>
------------------------------

I am quering the information as so :

  Dim dgItem As DataGridItem
        'Loops through each item in the datagrid to update the records
        For Each dgItem In dgList.Items
            strSql = CType(dgItem.Cells(2).FindControl("CP_In"), eWorld.UI.CalendarPopup).SelectedDate()
            strSql = CType(dgItem.Cells(3).FindControl("CP_Out"), eWorld.UI.CalendarPopup).SelectedDate()
            strSql = CType(dgItem.Cells(4).FindControl("DaysInProgress"), TextBox).Text
            strSql = CType(dgItem.Cells(5).FindControl("Description"), TextBox).Text
            strSql = CType(dgItem.Cells(6).FindControl("ID"), TextBox).Text
        Next

they all work, except for the "ID" -- if it is invisible. If it is visible, then the above works. Is there any way I can query the row, or pass the value in such a way that the datagrid stores the value, but doesnt display it.

oh, and on an unrelated question, anyway to tab inside this form ? it gets anyone trying to tab things and not be able to lol

thanks,
Cristian
0
Term56
Asked:
Term56
  • 2
  • 2
  • 2
1 Solution
 
rodmjayCommented:
The best way to do this is to use a datalist.  Here is all the info you should need on how to use it

http://msdn2.microsoft.com/en-US/library/system.web.ui.webcontrols.basedatalist.datakeyfield.aspx
0
 
rodmjayCommented:
The two tricks are to use a datalist and set the datakeyfield property to 'ID' or whatever your primary key field is.  From here you can get the id throug code using code like this

row = dt.Rows.Find(ItemsGrid.DataKeys(e.Item.ItemIndex))

Using a datalist is very similar to a datagrid, so there should not be any problems making the change.
0
 
RamuncikasCommented:
If you would use simple column for ID it would work no matter if ID column is visible of not. I don't think you should put ID into textbox unless users have ability to edit the ID. If you'd use simple bound column, then you'd be able to reference the column like this:

strSql = dgItem.Cells(6).Text
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Term56Author Commented:
ramuncikas, could you give me an example. would I give the boundcolumn the text of the ID ?
0
 
RamuncikasCommented:
I have no VS.NET at home, and only next tuesday I'll be at work.

If you're using VS.NET then go to colums designer and add a databound column and assign it's data field property to ID.
0
 
Term56Author Commented:
Thank you Ramuncikas, the following was the solution :

<asp:BoundColumn Visible="False" DataField="ID"></asp:BoundColumn>

strSql = dgItem.Cells(6).Text
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now