How to set SelectedValue of DropDownList in GridView EditTemplate

后端 未结 5 995
被撕碎了的回忆
被撕碎了的回忆 2021-01-04 20:36

I am trying to do this as asked earlier. The only difference that I found is additional List item that was included in above code.

I tried to use AppendDataBou

5条回答
  •  一整个雨季
    2021-01-04 21:02

    This is the best i have found....

    protected void GridView1_DataBound(object sender, EventArgs e)
    {
        foreach (GridViewRow gvRow in GridView1.Rows)
        {
            RadioButtonList rbl = gvRow.FindControl("rblPromptType") as RadioButtonList;
            HiddenField hf = gvRow.FindControl("hidPromptType") as HiddenField;
    
            if (rbl != null && hf != null)
            {
                if (hf.Value != "")
                {
                    //clear the default selection if there is one
                    rbl.ClearSelection();
                }
    
                rbl.SelectedValue = hf.Value;
            }
        }
    }
    

提交回复
热议问题