Ghost
Ghost

Reputation: 223

How to get value in drop down-list from parent Grid-view when Click Edit on child grid-view?

I have nested grid-view. In Parent grid View when I Click to Expand the gridview the child gridview shows the related data. But when I click to Edit Child grid view The values go to textbox outside the gridview but not in dropdown list.

I have tried

 protected void gvSub_RowEditing(object sender, GridViewEditEventArgs e)
{
    GridView gvSub = sender as GridView;
    GridViewRow row = gvSub.Rows[e.NewEditIndex];

    Int32 a = Convert.ToInt32(gvSub.DataKeys[e.NewEditIndex][0]);
    TextBox1.Text = ((Label)row.FindControl("lblName")).Text;
    TextBox2.Text = ((Label)row.FindControl("lblPrice")).Text;
    TextBox3.Text = ((Label)row.FindControl("qty")).Text;

    String Cate = ((Label)gvSub.Parent.FindControl("lblCtName")).Text;
    DropDownList1.Items.FindByValue(Cate.ToString()).Selected = true;  

    btnSub.Text = "Update";
    e.Cancel = true;
}

Parent Gridview Value fetched in Cate but not getting in dropdownlist

Upvotes: 0

Views: 179

Answers (1)

user10073871
user10073871

Reputation:

Change the "DropDownList1.Items.FindByValue" to "DropDownList1.Items.Add"

Upvotes: 1

Related Questions