Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Determine which button was clicked
Message
De
06/03/2007 09:45:10
Jerry Tovar
Dana Corporation Dana It
Maumee, Ohio, États-Unis
 
 
À
06/03/2007 08:58:36
Alexandre Palma
Harms Software, Inc.
Alverca, Portugal
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Versions des environnements
Environment:
ASP.NET
Divers
Thread ID:
01200831
Message ID:
01201016
Vues:
30
Alexandre,

I tried that. But I always get a blank value when I set the PK column "Visible" property to FALSE. Here is my RowCommand code:
//GridView1_RowCommand1(object sender, GridViewCommandEventArgs e)
string lc_button = e.CommandName; //Capture button
int index = Convert.ToInt32(e.CommandArgument);
GridViewRow row = this.GridView1.Rows[index];  //Get grid row.
string lc_pk = this.GridView1.Rows[index].Cells[0].Text; //Get PK value.
If I set the PK column "Visible" to TRUE, then the above works but my PK column is seen. This seems like it should work but I must be missing something.

I have discovered the DataKeys property of the GridView. I have gotten the following to work without having to add my PK to the GridView:
//GridView1_RowCommand1(object sender, GridViewCommandEventArgs e)
string lc_command = e.CommandName;  //Capture button
int index = Convert.ToInt32(e.CommandArgument); //Get grid row.
//Get PK value. WORKS!
int ln_ncode = Int32.Parse(this.GridView1.DataKeys[index].Value.ToString());
Do you see any harm in the above method?

Thanks,

Jerry



>Jerry why don't you add the PK field into the grid and put the visible property of the column to false, that's what I always do.
>
>>William,
>>
>>Yes, the RowCommand (e.CommandName) will tell me which button was clicked, but it won't pass the table's primary key value like it does with the SelectedIndexChanged event and (this.GridView1.SelectedValue).
>>
>>I know that with RowCommand I can get a value in the grid with:
>>
>>int index = Convert.ToInt32(e.CommandArgument);
>>GridViewRow row = this.GridView1.Rows[index];
>>
>>But I need to get the primary key field which is not displayed in the grid.
>>
>>My grid actually has a four buttons which perform four different functions. All the functions need the primary field value. I like the SelectedIndexChanged event because of the SelectedValue property, but that would mean all four buttons need the "CommandName" property set to "SELECT". This gives me the primary key value in SelectedValue but then I can't tell which button the user pressed.
>>
>>Perhaps there is a better way of doing this?
>>
>>Thanks,
>>
>>Jerry
>>
>>
>>
>>
>>>>I have a webform with a gridview that has 4 columns. Two of the columns are "ButtonField". One button is for Edit, one is button is for Delete. Both buttons's "CommandName" contains "SELECT". The SelectedIndexChanged of the grid points to "MyMethod()".
>>>>
>>>>When I run the form and click on either button, "MyMethod()" gets control, but how can I tell which button was pressed, the Edit or the Delete?
>>>>
>>>>Or is there a better way to do this?
>>>>
>>>>Thanks,
>>>>
>>>>Jerry
>>>
>>>Check out the RowCommand method of a grid.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform