Bonjour,
voilà j ai créé un gridview en ASP et j y ai mis 2 buttonfield: Un pour supprimer, un pour mettre à jour!
J utilise pas la DeleteCommand, parcequ il faut que je supprime dans plusieurs tables en meme temps!
Maintenant j aimerai savoir sur l evenement RowCommand , comment différencier les 2 boutons!
voilà une idée mais je la trouve pas logique...lol
--------------- code asp (ça c est correct))-------------------------------------------
<
asp:GridViewID="GridView2"runat="server"AutoGenerateColumns="False"CellPadding="4"
DataKeyNames="ID_GROUP"DataSourceID="SourceGroup2"ForeColor="#333333"GridLines="None"
Width="311px">
<FooterStyleBackColor="#507CD1"Font-Bold="True"ForeColor="White"/>
<Columns>
<asp:BoundFieldDataField="ID_GROUP"HeaderText="ID_GROUP"ReadOnly="True"SortExpression="ID_GROUP"/>
<asp:BoundFieldDataField="TITLE_GROUP"HeaderText="TITLE_GROUP"SortExpression="TITLE_GROUP"/>
<asp:BoundFieldDataField="DESC_GROUP"HeaderText="DESC_GROUP"SortExpression="DESC_GROUP"/>
<asp:ButtonFieldButtonType="Button"Text="Delete"HeaderText="Select"/>
<asp:ButtonFieldButtonType="Button"Text="Update"HeaderText="Select"/>
</Columns><RowStyleBackColor="#EFF3FB"/>
<EditRowStyleBackColor="#2461BF"/>
<SelectedRowStyleBackColor="#D1DDF1"Font-Bold="True"ForeColor="#333333"/>
<PagerStyleBackColor="#2461BF"ForeColor="White"HorizontalAlign="Center"/>
<HeaderStyleBackColor="#507CD1"Font-Bold="True"ForeColor="White"/>
<AlternatingRowStyleBackColor="White"/></asp:GridView><asp:SqlDataSourceID="SourceGroup2"runat="server"ConnectionString="<%$ ConnectionStrings:ConnectionString3 %>"
ProviderName="<%$ ConnectionStrings:ConnectionString3.ProviderName %>"SelectCommand='SELECT "ID_GROUP", "TITLE_GROUP", "DESC_GROUP" FROM "GROUP_QUEST"'>
</asp:SqlDataSource>
------------------------------------------------------------------------------------------
--------------- code c# , c est celui là qui va pas -------------------------------------------------------
C'est dans la partie en gras que je sais pas trop ! je voudrais appeler le bouton Delete et pas le Update
protected
void GridView2_RowCommand(object sender, GridViewCommandEventArgs e)
{
ButtonField Button_grid = newButtonField();
// to convert the argument for the event in a String
int index = Convert.ToInt32(e.CommandArgument);
GridViewRow row = GridView2.Rows[index];
// All the values of each column of the row selected are put in a variable
TableCell paramId= row.Cells[0];
TableCell paramTitle = row.Cells[1];
TableCell paramDesc = row.Cells[2]; if (Button_grid.Text=="Delete")
{
// connection to MPL database
DataConnection m = newDataConnection();
OracleConnection conn = null;
conn = m.DoConnection();
try
{
// create command
// command for DELETE FROM group_quest OracleCommand cmd = conn.CreateCommand();
// commande for COMMIT
OracleCommand cmd2 = conn.CreateCommand();
// command for DELETE FROM question
OracleCommand cmd3 = conn.CreateCommand(); cmd.CommandText =
"DELETE FROM group_quest where title_group=:parm1, desc_group=:parm2";
// use to save data in the database
cmd2.CommandText = "COMMIT";
cmd3.CommandText = "DELETE FROM question where id_group=:parm3"; OracleParameter myParameter1 = newOracleParameter(":parm1", OracleType.VarChar, 300);
myParameter1.Value = paramTitle.Text;
OracleParameter myParameter2 = newOracleParameter(":parm2", OracleType.VarChar, 300);
myParameter2.Value = paramDesc.Text;
OracleParameter myParameter3 = newOracleParameter(":parm3", OracleType.Number);
myParameter3.Value = paramId.Text; // add parameters to the query
cmd.Parameters.Add(myParameter1);
cmd.Parameters.Add(myParameter2);
cmd3.Parameters.Add(myParameter3); // execute the query
cmd.ExecuteNonQuery();
cmd3.ExecuteNonQuery();
cmd2.ExecuteNonQuery(); cmd.Dispose();
cmd =
null;
cmd3.Dispose();
cmd3 = null;
cmd2.Dispose();
cmd2 = null;
}...... catch.... finally}}
MERCI
Sabine