Thank you for help, but not working.. 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 (off the gridview).
<asp:ImageButton ID="btnReco"
ImageUrl="/aspnet/img/recovery_button.gif"
runat="server"
OnClick="btnReco_Click"
CommandArgument="1"
CssClass="ddl_Class_new"
Visible="true" />
The dropdownlist from each row of gridview are empty... even if the value stored in the table is OK or KO.
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)
{
//Find the DropDownList in the Row.
DropDownList ddl1 = (e.Row.FindControl("ddl1") as DropDownList);
ddl1.DataSource = GetData("SELECT DISTINCT t1 FROM `tb_1` WHERE t1 = '" + Ticket.ToString() + "';");
ddl1.DataTextField = "t1";
ddl1.DataValueField = "t1";
ddl1.DataBind();
//Add Default Item in the DropDownList.
ddl1.Items.Insert(0, new ListItem("[ === === === ]"));
//Select the Country of Customer in DropDownList.
string t1 = (e.Row.FindControl("t1") as Label).Text;
ddl1.Items.FindByValue(t1).Selected = true;
}
}
}
<asp:TemplateField
HeaderText="t1"
ItemStyle-CssClass="ddl_Class_new"
ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:Label ID="lbl_ddl1" runat="server" Text='<%# Eval("t1") %>' Visible = "false" />
<div>
<asp:DropDownList ID="ddl1" runat="server"
AutoPostBack="true"
OnSelectedIndexChanged="ddl1_SelectedIndexChanged"
BackColor="Yellow"
CssClass="ddl_Class_new">
<asp:ListItem Text="[ === === === ]" Value=""></asp:ListItem>
<asp:ListItem Text="OK" Value="OK"></asp:ListItem>
<asp:ListItem Text="KO" Value="KO"></asp:ListItem>
</asp:DropDownList>
</div>
</ItemTemplate>
</asp:TemplateField>