Re: bug? cannot get value of cell on invisible column



Have you tried using the DatakeyNames property of the gridview and then
accessing the selectedrows datakeyvalue?

Something like this: In the SelectedIndexChangedEvent
Me.gv.SelectedDataKey.Item(0).ToString

Ross


"Beemer Biker" <jstateson@xxxxxxxx> wrote in message
news:1334djrdvnqu314@xxxxxxxxxxxxxxxxxxxxx
This is strange - I have a grid with columns: id, authString, realName,
lastLogin, administrator, files_path_prefix

id is a primary key in sql table. I didn't want the id to show up when
clicking on gridview "edit" command so I made that column invisible. This
works nicely and one does not see the id field when the grid is displayed
nor is it editable.

But now I cannot programmatically subscript cell and pull out the value of
the id ...bug or feature??

GridView4Users.Rows[i].Cells[idID].Text.ToString() is ""
instead of the string value of the user id. As soon as I make the column
visible the value then shows up eg: "4" instead of "" if id value was 4


Then I made the column visible but the field readonly and that caused the
sql "update" command to fail as the update command skipped over that "id"
field and put "authString" where id was supposed to go causing an
exception on the sqlserver.

UPDATE "Users" SET "authString"=?,
"realName"=?,"lastLogin"=?,"administrator"=?, "files_path_prefix"=? WHERE
"id" = ?

Looking at the server, WHERE "id" = someones-name shows up instead of
WHERE "id" = 4 anytime I make that field read-only.
I tried changing the order of the parameters leaving some out putting id
in twice, everying I could think of but never got the correct setting to
allow the sql command to execute. This is what it looks like when it is
working and visible.
http://stateson.net/pub/bug_sql_r19.png

Is there some other way to get the value of that id field and still have
the column invisible to the user? Can I do something programmatically
like set ...row[i].Selected=True; and then get the value from
sqlDataSource? Alternately, I can put id values into a databound list and
access that list instead of the grid. Just got to make that list 1 px
wide so no one can see it (??)

note that i am using postgresql and not mssql.

--
======================================================================
Joseph "Beemer Biker" Stateson
http://TipsForTheComputingImpaired.com
http://ResearchRiders.org Ask about my 99'R1100RT
======================================================================





.



Relevant Pages

  • RE: Gridview not updating the database
    ... It looks like you are not setting DataKeyNames property for the GridView. ... This property represents the primary key ... <SelectParameters> ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: GridView and TemplateField Help
    ... The DataKeyNames property of the GridView tells it which fields in the data that it's dealing with are the primary key fields. ... If yes, then the only slightly reasonable explanation that I can think of is the usage of System.Reflection by the GridView to invoke the Delete method, wherein it specifies the argument value as well as name, based upon what it has been passed in the DataKeyNames property. ... And I then get the error "could not find a non-generic method 'DeleteActivity' that has parameters: ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Gridview and bound field hidden
    ... Preferred choice would be to use DataKeyNames property of GridView and ... then access it through GridView's key collection. ... If that is not possible then a TemplateField may be used with a ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: looking for a special kind of table control
    ... if you have PrimaryKey values which shouldn't be updatable, ... fields to the DataKeyNames property on your GridView. ... Prev by Date: ...
    (microsoft.public.dotnet.framework.aspnet.webcontrols)

Loading