Hi,
I am using a dropdownlist inside a datagrid in my asp.net application. When the user cick on the edit button in a datagrid, I want to show the previously saved item as selected in a dropdownlist. I am using the below code to select item in the dropdownlist. Its working file if the items bind to the dropdownlist is same and in the same case when comparing with the previously saved item. But its failing when the case is not matching. Can some one please check the below code and help to select the item in a dropdownlist without checking the case of items.
protected void OnRowDataBound(object sender, GridViewRowEventArgs e)
{
DataRowView drv = e.Row.DataItem as DataRowView;
if (e.Row.RowType == DataControlRowType.DataRow)
{
DropDownList ddltemptable = (DropDownList)e.Row.FindControl("ddltemptablename");
DataTable dttemptable = load_temptable();
ddltemptable.DataSource = dttemptable;
ddltemptable.DataTextField = "table_name";
ddltemptable.DataValueField = "table_name";
ddltemptable.DataBind();
string selectedtemptable = DataBinder.Eval(e.Row.DataItem, "TempTableName").ToString();
ddltemptable.Items.Insert(0, new ListItem("-Select-", "0"));
if (selectedtemptable != "")
ddltemptable.Items.FindByText(selectedtemptable).Selected = true;
else
{
ddltemptable.ClearSelection();
ddltemptable.Items.FindByText("-Select-").Selected = true;
}
}
}
Mohammad HussainPosted Aug 3, 2023, 2:37 PM
TRY THIS PELASE.
AnuPosted Aug 3, 2023, 2:46 PM
Thanks,it worked
AnuPosted Aug 3, 2023, 2:33 PM
Thanks for looking into this. I tried the code you suggested. But I am getting below error
No overload for method 'FindByText' takes 2 arguments
Mohammad HussainPosted Aug 3, 2023, 1:56 PM