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_De lete" 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).Find Control("C P_In"), eWorld.UI.CalendarPopup).S electedDat e()
strSql = CType(dgItem.Cells(3).Find Control("C P_Out"), eWorld.UI.CalendarPopup).S electedDat e()
strSql = CType(dgItem.Cells(4).Find Control("D aysInProgr ess"), TextBox).Text
strSql = CType(dgItem.Cells(5).Find Control("D escription "), TextBox).Text
strSql = CType(dgItem.Cells(6).Find Control("I D"), 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
<asp:datagrid id="dgList" OnDeleteCommand="dgList_De
<Columns>
<asp:TemplateColumn HeaderText="Sequence">
<ItemTemplate>
<asp:DropDownList ID="Sequence" Runat="server" DataSource = '<%# Get_Schedule_Numbers() %>' SelectedIndex = '<%# DataBinder.Eval(Container,
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateColumn>
(A few more inbetween)
<asp:TemplateColumn Visible = False>
<ItemTemplate>
<asp:TextBox Runat="server" ID="ID" text='<%# DataBinder.Eval(Container,
</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).Find
strSql = CType(dgItem.Cells(3).Find
strSql = CType(dgItem.Cells(4).Find
strSql = CType(dgItem.Cells(5).Find
strSql = CType(dgItem.Cells(6).Find
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
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.Dat aKeys(e.It em.ItemInd ex))
Using a datalist is very similar to a datagrid, so there should not be any problems making the change.
row = dt.Rows.Find(ItemsGrid.Dat
Using a datalist is very similar to a datagrid, so there should not be any problems making the change.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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.
ASKER
Thank you Ramuncikas, the following was the solution :
<asp:BoundColumn Visible="False" DataField="ID"></asp:Bound Column>
strSql = dgItem.Cells(6).Text
<asp:BoundColumn Visible="False" DataField="ID"></asp:Bound
strSql = dgItem.Cells(6).Text
http://msdn2.microsoft.com/en-US/library/system.web.ui.webcontrols.basedatalist.datakeyfield.aspx