Hi there,
I need to retrieve some records if existing in a mysql database table and populate a gridview, which is initially populated with random data.
This is why I included this button on the web page, using CommandArgument
<asp:ImageButton ID="btnReco"
ImageUrl="/aspnet/img/recovery_button.gif"
runat="server"
OnClick="btnReco_Click"
CommandArgument="1"
ToolTip="Indietro"
CssClass="ddl_Class_new"
Visible="true" />
And on the OnClick event this
protected void btnReco_Click(object sender, ImageClickEventArgs e)
{
int t = Convert.ToInt32(MaP.Base64ForUrlDecode(Request.QueryString["t"].ToString()));
switch (t)
{
case 1:
gvProducts.DataSource = RetrieveProducts_reco();
gvProducts.DataBind();
}
}
private DataTable RetrieveProducts_reco()
{
if (!String.IsNullOrEmpty(MaP.Container.TheObjectP))
{
DataTable dt = new DataTable();
DataSet ds = new DataSet();
using (MySqlConnection myConnectionString =
new MySqlConnection(ConfigurationManager.ConnectionStrings["cn"].ConnectionString))
{
using (MySqlCommand cmd =
new MySqlCommand("sp_20240311", myConnectionString))
{
cmd.CommandTimeout = 2147483;
cmd.Connection.Open();
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Clear();
MySqlDataAdapter adapter =
new MySqlDataAdapter(cmd);
if (!String.IsNullOrEmpty(Request.QueryString["ut"].ToString()))
{
cmd.Parameters.AddWithValue("@spCCO",
MaP.Base64ForUrlDecode(Request.QueryString["ut"].ToString()));
}
adapter.Fill(ds);
if (ds.Tables.Count > 0)
{
dt = ds.Tables[0];
....
}
}
}
return dt;
}
else
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "Alert", "alert('KO');" +
"window.location='http://..../';", true);
return null;
}
}
On this gridview there is a dropdownlist that should be populated when the recovery button is clicked with the value stored in database
I tried this solution without success because the value of the CommandArgument from recovery button is empty.
protected void gvProducts_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string Ticket = e.Row.Cells[1].Text;
ImageButton imgBtn = (ImageButton)e.Row.FindControl("btnReco");
if (imgBtn != null)
{
string imgBtnReco = imgBtn.CommandArgument;
Response.Write(imgBtnReco.ToString()); Response.End();
}
}
}
I'm not sure if this is the right approach, that's why I ask you for help in solving this problem, thanks