如何在逗号视图中填充逗号分隔的字符串到checkboxlist

时间:2016-05-09 11:28:08

标签: division

protected void MYgrid_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.Footer)
    {
        DropDownList ddlC = (DropDownList)e.Row.FindControl("ddlCountry1");
        DropDownList ddlS = (DropDownList)e.Row.FindControl("ddlState1");
        if (ddlC != null)
        {
            BindCountry(ddlC, ddlS);
        }
    }
    if (e.Row.RowType == DataControlRowType.DataRow && MYgrid.EditIndex == e.Row.RowIndex)
    {
        DropDownList ddlC = (DropDownList)e.Row.FindControl("ddlCountry");
        DropDownList ddlS = (DropDownList)e.Row.FindControl("ddlState");
        if (ddlC != null)
        {
            cmd = new SqlCommand("select * from M_Country", con);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataTable dt = new DataTable();
            da.Fill(dt);
            ddlC.DataSource = dt;
            ddlC.DataTextField = "CountryName";
            ddlC.DataValueField = "C_ID";
            ddlC.DataBind();
            ddlC.Items.FindByText((e.Row.FindControl("lblCountry") as Label).Text).Selected = true;
        }
        if (ddlS != null)
        {
            cmd = new SqlCommand("select * from M_State", con);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataTable dt = new DataTable();
            da.Fill(dt);
            ddlS.DataSource = dt;
            ddlS.DataTextField = "StateName";
            ddlS.DataValueField = "S_ID";
            ddlS.DataBind();
            ddlS.Items.FindByText((e.Row.FindControl("lblState") as Label).Text).Selected = true;
        }
        RadioButtonList rblG = (RadioButtonList)e.Row.FindControl("rblGender");
        rblG.Items.FindByText((e.Row.FindControl("lblGender") as Label).Text).Selected = true;
        CheckBoxList chkH = (CheckBoxList)e.Row.FindControl("chkHobby");
        Label ll = (Label)e.Row.FindControl("lblHobby");
        string ss = ll.Text;
        string[] ss1 = ss.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
        foreach (string ss2 in ss1)
        {
            for (int i = 0; i < 2; i++)
            {
                if (ss2 == chkH.Items[i].Text)
                {
                    chkH.Items[i].Selected = true;
                }
            }
        }
    }
}

0 个答案:

没有答案