views:

173

answers:

1

I need to limit the values in a data bound drop down placed in a template column in a gridview based on the text in another column in that row of the gridview. I also want the dropdown to be databound. Aparently, these two things are not possible at the same time as it gives a data bind error. I think .net prevents it because there is a likelihood of a valid value appearing in the database which doesnt exist in the drop down.

How can I accomplish this using a drop down or any other method.

Kindly help.

A: 

You can limit the value of databound dropdown by filtering the data to be displayed based on the values entered on the textbox right?

On the event grd_RowDataBound put the ff: test code

protected void grd_RowDataBound(object sender, GridViewRowEventArgs e)
{
    TextBox txt = (TextBox)e.Row.FindControl("txt");
    DropDownList cbo = (DropDownList)e.Row.FindControl("cbo");

    if (cbo != null)
    {
        cbo.DataSource = _data.getData(txt.Text); //returns filterered datatable based on txt value
        cbo.DataTextField = "ListName";
        cbo.DataValueField = "ListID";
        cbo.DataBind();
    }
}
Peter Ramos