基于sp列表项的值将复选框列表值绑定到网格视图 [英] To bind check box list value to grid view based on value of sp list item

查看:97
本文介绍了基于sp列表项的值将复选框列表值绑定到网格视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用行数据绑定获取值表单列表项到网格视图控件。对于radio-list它工作正常但是对于复选框列表和下拉列表选择的值应该在网格视图上检查相应的控件。

我调试了条件,每件事都运行正常,但我在编辑时无法在网格视图上找到选定的值。

网格视图是在可视化Web部件上实现的。



请告诉我在哪里检查和做什么。



我尝试了什么:



我的代码:

protected void grid_RowDataBound(object sender,GridViewRowEventArgs e)

{

if(e.Row.RowType == DataControlRowType.DataRow&& grid.EditIndex == e.Row.RowIndex)

{







string id = grid.DataKeys [e.Row.RowIndex] .Value.ToString();



RadioButtonList rb =(RadioButtonList)e.Row.FindControl(RadioB uttonList1);

CheckBoxList chkdept =(CheckBoxList)e.Row.FindControl(CheckBoxList1);

DropDownList ddl =(DropDownList)e.Row.FindControl( DropDownList1);

SPWeb currentWeb = SPContext.Current.Web;
SPList lst = currentWeb.Lists [Employee];

SPListItem item = null;

item = lst.GetItemById(Convert.ToInt32(id));



string rd = item [Gender ] .ToString();





string ex = item [Experience]。ToString();

string replace = ex.TrimStart(';','#')。TrimEnd(';','#');

string qul = item [Qualification]。ToString() ;

ddl.Items.FindByText(qul).Selected = true;



if(rd ==Male)

{

rb.Items.FindByText(rd).Selected = true;

}



else if(rd ==Female)

{

rb.Items.FindByText(rd).Selected = true;



}





if(replace ==1 - 2年)

{

chkdept.Items .FindByText(替换).Selected = true;



}

else if(replace ==2-5year)

{



chkdept.Items.FindByText(替换).Selected = true;



}

否则(替换==5 - 10年)

{




chkdept.Items.FindByText(替换).Selected = true;

}



}

}

I used row data bound to get value form list item to grid view controls.For radio-list it works fine but for checkbox list and drop-down list selected value should be checked on grid view corresponding controls.
I debugged the conditions every thing works fine but I can't find selected values on grid-view while editing.
Grid view was implemented on visual web part.

Please let me know where to check and what to do.

What I have tried:

My code:
protected void grid_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow && grid.EditIndex == e.Row.RowIndex)
{



string id = grid.DataKeys[e.Row.RowIndex].Value.ToString();

RadioButtonList rb = (RadioButtonList)e.Row.FindControl("RadioButtonList1");
CheckBoxList chkdept = (CheckBoxList)e.Row.FindControl("CheckBoxList1");
DropDownList ddl = (DropDownList)e.Row.FindControl("DropDownList1");
SPWeb currentWeb = SPContext.Current.Web;
SPList lst = currentWeb.Lists["Employee"];
SPListItem item = null;
item = lst.GetItemById(Convert.ToInt32(id));

string rd = item["Gender"].ToString();


string ex = item["Experience"].ToString();
string replace = ex.TrimStart(';', '#').TrimEnd(';', '#');
string qul = item["Qualification"].ToString();
ddl.Items.FindByText(qul).Selected = true;

if (rd == "Male")
{
rb.Items.FindByText(rd).Selected = true;
}

else if (rd == "Female")
{
rb.Items.FindByText(rd).Selected = true;

}


if (replace == "1-2year")
{
chkdept.Items.FindByText(replace).Selected = true;

}
else if (replace == "2-5year")
{

chkdept.Items.FindByText(replace).Selected = true;

}
else if (replace == "5-10year")
{


chkdept.Items.FindByText(replace).Selected = true;
}

}
}

推荐答案

我尝试了一点点调试,然后找到了解决方案。





if(replace ==1 - 2年)

{

/*chkdept.Items.FindByText(replace).Selected = true; * /

而不是上面的代码只是替换为这个

chkdept.Items [0] .Selected = true;



}

否则如果(替换==2-5岁)

{



chkdept .Items [1] .Selected = true;



}

else if(replace ==5-10year)

{





chkdept.Items [2] .Selected = true;

}



string ex = item [Experience]。ToString();



获取列表时选项字段中的字符串对象中的项目复选框列表共享点。默认情况下它带有空格,如:2 - 5年而不是2 - 5年。所以我通过字符串,空间工作完美。
I tried little bit of debugging, then found solution.


if (replace == "1-2year")
{
/*chkdept.Items.FindByText(replace).Selected = true;*/
instead of above code just replaced with this
chkdept.Items[0].Selected = true;

}
else if (replace == "2-5year")
{

chkdept.Items[1].Selected = true;

}
else if (replace == "5-10year")
{


chkdept.Items[2].Selected = true;
}

string ex = item["Experience"].ToString();

Also while getting list item in string object from choice field check box List Share Point.On default it comes with space like : "2-5 year" instead of "2-5year".So I passed with string with space worked perfectly.


这篇关于基于sp列表项的值将复选框列表值绑定到网格视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆