Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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;
}

}
}
Posted
Updated 6-Feb-17 0:02am
Comments
Karthik_Mahalingam 5-Feb-17 7:08am    
is it throwing any error?
check the case of the item text and the selected text.
narengowtham 5-Feb-17 7:16am    
It's not throwing a error,for radio button I can set the value it work's fine and for checkbox list it checks conditions and it not getting into the chkdept.Items.FindByText(replace).Selected = true;
narengowtham 5-Feb-17 7:18am    
I checked with bound values and field name every thing fine.
Karthik_Mahalingam 5-Feb-17 7:18am    
does the item present in the checkbox list
narengowtham 5-Feb-17 7:21am    
<asp:TemplateField HeaderText="Gender" ItemStyle-Width="10" ItemStyle-Wrap="False">
<ItemTemplate >
<%# Eval("Gender") %>

<edititemtemplate>

<asp:RadioButtonList ID="RadioButtonList1" runat="server" RepeatDirection="Horizontal" >
<asp:ListItem Value="1">Male
<asp:ListItem Value="2" >Female



<asp:TemplateField HeaderText="Experience">
<itemtemplate>
<%# Eval("Experience") %>

<edititemtemplate>
<asp:CheckBoxList ID="CheckBoxList1" runat="server">
<asp:ListItem Value="0" Text="1-2year">
<asp:ListItem Value="1" Text="2-5year">
<asp:ListItem Value="2" Text="5-10year">








My share point lsitem column name Experience choice field
Same as
1-2year
2-5year
5-10year.
But on grid view check box value shows with;,#
special chracter.
2-5year

1 solution

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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900