Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I have a datagrid with a hidden col

Status
Not open for further replies.

netangel

Programmer
Feb 7, 2002
124
PT
I have a datagrid with a hidden colunm (the first column) and a visible one.
My hidden column is the id of my table and the visible one is the description
If I use a UpdateCommand event in the datagrid, I can get the new value of the visible column (it has a textbox), but I can't find the value of the hidden one.
Both columns are bound columns.

How can I find the value of the hidden column, so I can update the table?
NetAngel
 
Where and how are you trying to grab the value of that column? It should be accessible (assuming it's the first column in the grid) via an event handler of the datagrid with:

e.item.cells(0).text

what's your code look like?
penny1.gif
penny1.gif
 
That expression (e.item.cells(0).text) returns a empty string. If I turn the visible to true, I can see it has the right value. It's not a binding problem.

This is my grid:

<asp:DataGrid id=&quot;grdTemas&quot; runat=&quot;server&quot; AutoGenerateColumns=&quot;False&quot;>
<Columns>
<asp:BoundColumn Visible=&quot;False&quot; DataField=&quot;IDTema&quot;></asp:BoundColumn>
<asp:EditCommandColumn ...></asp:EditCommandColumn>
<asp:TemplateColumn HeaderText=&quot;Tema&quot;>...</asp:TemplateColumn>
</Columns>
</asp:DataGrid></P>


And this is my UpdateCommand event code:

Dim novoTemaDescricao As String
novoTemaDescricao = CType(e.Item.Cells(4).FindControl(&quot;txtTemaDescricao&quot;), TextBox).Text

'Update DB
ExecuteSQL(&quot;UPDATE bugTema &quot; & _
&quot;SET Descricao = '&quot; & novoTemaDescricao & &quot;' &quot; & _
&quot;WHERE IDTema = &quot; & e.Item.Cells(0).Text)

'tryed this too - doen't work either
'&quot;WHERE IDTema = &quot; & CType(e.Item.Cells(0).Controls(0), TextBox).Text)

grdTemas.EditItemIndex = -1
grdTemas.DataBind()

Any sugestions?
NetAngel
 
Ok, I went back into my code where I use this method, and I see what's happening here.

The problem is that when you set visible = false, it's really not even sent to the client, and therefore, it's really just not there.

If you turn it to visible = true, and try the same code, it would work.

That said, in my case, I'm actually grabbing that value in the onItemDataBound event, when it is still there (I think it's trashed after the page_prerender event), so you have yourself a little bit of trouble here.

I would suggest the following:

create an onItemDataBound event if you don't already have one, and put the following code there:

if e.item.itemType = ListItemType.EditItem then
session(&quot;editRowKey&quot;) = e.item.cells(0).text
end if

Then, whatever row is in edit mode, the key value for that row will be in that session variable, which you'll be able to evaluate in your update method.

hth! :)
paul
penny1.gif
penny1.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top