如何编辑gridview字段

时间:2013-02-04 11:12:07

标签: asp.net gridview

  

我有 gridview ,我添加了编辑功能来更新网格内容,因为当用户点击编辑按钮面板显示字段有网格内容并且用户可以编辑数据时,其中一个数据下拉有位置数据。 但是当我点击编辑按钮时,所有字段都有网格内容,但DDL第一次有第一个项目,当我再次点击编辑时,DDL有正确的项目。这是什么问题?

 protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
    if (e.CommandName == "editrow")
    {
        GridViewRow row = (GridViewRow)(((ImageButton)e.CommandSource).NamingContainer);

        TextBox name = row.FindControl("Lbl_Name") as TextBox;

        TextBox address = row.FindControl("Lbl_Address") as TextBox;
        Label mobile = row.FindControl("Lbl_Mobile") as Label;
        Label tele = row.FindControl("Lbl_Tele") as Label;

        Label area = row.FindControl("Lbl_Area_ID") as Label;
        Label location = row.FindControl("Lbl_Loc_ID") as Label;
        Label category = row.FindControl("Lbl_Cat_ID") as Label;


        txt_adr.Text = address.Text;
        txt_mobile.Text = mobile.Text;
        txt_name.Text = name.Text;
        txt_tele.Text = tele.Text;
        ddl_category.SelectedValue = category.Text;
        //the problem here on ddloc
        ddloc.SelectedValue = location.Text;

        DDL_AREA.SelectedValue = area.Text;




    }
}

1 个答案:

答案 0 :(得分:0)

而不是

ddloc.SelectedValue = location.Text;

使用

ddloc.Selecteditem.Text = location.Text;