Here's an answer to anyone that follows this thread.
You can indeed grab the values associated with GridView command functions
such as "edit" and "update" and "select", and you can handle those events
with your own custom code.
GridViews raise an event called "SelectedIndexC hanged" when different events
are selected by the user. In codebehind, you can write a function to be
called on this event:
protected void GridView1_Selec tedIndexChanged (object sender, EventArgs e)
{
EditItem();
}
The EditItem function can in turn read a property "GridView1.Sele ctedValue"
that is helpfully provided by the ASP.NET gridview, and in my case, I can
use that value to do the ORM stuff I want to do:
public void EditItem()
{
int idToEdit = Convert.ToInt32 (GridView1.Sele ctedValue);
Contentitems ci = new Contentitems();
ci.LoadByPrimar yKey(idToEdit);
.... etc.
The last step to making this work well is to make sure to rebind the data
grid after you're done doing whatever you're doing:
protected void SaveChanges_Cli ck(object sender, EventArgs e)
{
int idToEdit = Convert.ToInt32 (GridView1.Sele ctedValue);
Contentitems ci = new Contentitems();
ci.LoadByPrimar yKey(idToEdit);
ci.Con_Title = editTitle.Text;
....
ci.Save();
mv_MiddleBar.Se tActiveView(v_S preadsheetView) ;
GridView1.DataB ind();
}
Aside: I'm finishing the first really comprehensive/complicated app that
I've tried to build in ASP.NET 2, and my conclusion is that it is a very
capable, very reusuable, and very cool framework that demands a fairly high
level of skill and knowledge to use well. ASP was nice for programming
novices because you could sort of klutz around with it until it sort-of did
what you needed it to do. ASP.NET doesn't really have an effective "dummy
mode" as ASP did, and you need to be a modestly competant programmer to use
it well, especially if you want to go beyond pre-baked behaviors.
-KF
<ke*****@nospam .nospamwrote in message
news:%2******** *******@TK2MSFT NGP03.phx.gbl.. .
>I want to know how to make a clickable button or Command field on a
GridView, and have the user's action a) fire a function and b) pass a data
value from one of the GridView's columns to that function.
Long version: ASP.NET's usual paradigm with master-detail editing is to
have you define a commandfield, and on your detail view to define a second
datasource that uses the SelectedValue of the GridView to determine what
the detail record is.
I'm using an ORM framework and for whatever reason I would simply like to
a) grab the ContentID of the record selected on the GridView and b) use
that value to grab my detail view without going through SqlDataSource.
I could hack this up by just passing a QueryString parameter and posting
back to my form, but I'd prefer to know a more direct and less hack-y
approach.
Thanks for any help you can offer.
-KF