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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Gridview edit with hidden, readonly or both Primary Key 1

Status
Not open for further replies.

CassidyHunt

IS-IT--Management
Jan 7, 2004
688
US
This has probably been asked before although I didn't pull it up in a search but I have a gridview that I am editing. The datasource is an objectdatasource. If I have my primary key column hidden, readonly, or both then it will not pass that key to my parameters. However if I make visible and editable then it passes it fine.

Is there anyway around this?

Thanks

Cassidy
 
Either set the field as the pk on your GridView (by setting it as the sole member of the DataKeyNames array property) or hide it in a label or something in one of your other visible columns.
Code:
<!-- Set it as the datakeyname -->
<asp:gridview id="MyGridView" 
  datakeynames="PkFieldName"
  ...
  />

<!-- Pass it as a hidden label -->
  <TemplateColumn>
    <asp:Label id="lblPk" Text='<%# //inject your pk here %>' Visible="False" />
  </TemplateColumn>
.....
Either way will handle passing your pk around.

-paul

penny.gif
penny.gif

The answer to getting answered -- faq855-2992
 
If you aren't going to be showing the Primary Key at all, I'd go with the DataKeyNames approach.

link9 - Welcome back Paul, it's been a while since you've been on (at least in this forum anyway)...


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Awesome. And you think that would be a requirement of becoming an MCSD.

Thanks for the help.

Cassidy
 

Here seems to be the best explanation I have found. I modified my update query to have only the parameters I am displaying, and that works fine. Just stinks to have to maintain the update query based on what fields you have visible - and, I guess that keeps you from doing some things at runtime (as far as what fields are visible and what not).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top