Link to home
Start Free TrialLog in
Avatar of Term56
Term56

asked on

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
Avatar of rodmjay
rodmjay
Flag of United States of America image

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
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.
ASKER CERTIFIED SOLUTION
Avatar of Ramuncikas
Ramuncikas
Flag of Lithuania image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Term56
Term56

ASKER

ramuncikas, could you give me an example. would I give the boundcolumn the text of the ID ?
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.
Avatar of Term56

ASKER

Thank you Ramuncikas, the following was the solution :

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

strSql = dgItem.Cells(6).Text