Hi,
My assignment is to give edit functionality in a grid. when the user clicks on edit user will see textboxes and checkboxlists from which he can manipulate data.
In the Form template I have a CheckBoxList.
<EditFormSettings EditFormType = "Template">
<FormTemplate>
<asp:CheckBoxList ID= "List2" runat="server" selectedvalue = '<%# EVal("ApprovedValues")%>' datasource= "sqldatasource1"
datatextfield="value" datavaluefield= "value" tabindex="2">
</asp:heckBoxList>
my problem here is the approvedvalues that i get from the grid can look like a,b,c. I want to recognize all these values and select them from the list coming from sqldatasource1. Also if the approvedvalue has data that does not exist in the sqldatasource1 list I am getting an error.
"list2 has a selected value which is invalid because it does not exist in the list of items."
can anyone help?
Thanks
My assignment is to give edit functionality in a grid. when the user clicks on edit user will see textboxes and checkboxlists from which he can manipulate data.
In the Form template I have a CheckBoxList.
<EditFormSettings EditFormType = "Template">
<FormTemplate>
<asp:CheckBoxList ID= "List2" runat="server" selectedvalue = '<%# EVal("ApprovedValues")%>' datasource= "sqldatasource1"
datatextfield="value" datavaluefield= "value" tabindex="2">
</asp:heckBoxList>
my problem here is the approvedvalues that i get from the grid can look like a,b,c. I want to recognize all these values and select them from the list coming from sqldatasource1. Also if the approvedvalue has data that does not exist in the sqldatasource1 list I am getting an error.
"list2 has a selected value which is invalid because it does not exist in the list of items."
can anyone help?
Thanks
5 Answers, 1 is accepted
0

Jayesh Goyani
Top achievements
Rank 2
answered on 16 May 2012, 07:09 AM
Hello,
Thanks,
Jayesh Goyani
<
MasterTableView
DataKeyNames
=
"ApprovedValues"
>
<
asp:CheckBoxList
ID
=
"List2"
runat
=
"server"
datasource
=
"sqldatasource1"
datatextfield
=
"value"
datavaluefield
=
"value"
tabindex
=
"2"
>
protected
void
RadGrid1_ItemDataBound(
object
sender, GridItemEventArgs e)
{
if
(e.Item
is
GridEditableItem && e.Item.IsInEditMode)
{
//GridEditableItem item = e.Item as GridEditableItem;
GridEditFormItem item = e.Item
as
GridEditFormItem;
CheckBoxList List2 = item.FindControl(
"List2"
)
as
CheckBoxList;
string
strApprovedVlues = Convert.ToString(item.GetDataKeyValue(
"ApprovedValues"
));
if
(!
string
.IsNullOrEmpty(strApprovedVlues))
{
if
(strApprovedVlues.Split(
','
).Length > 0)
{
foreach
(
string
str1
in
strApprovedVlues.Split(
','
))
{
if
(List2.Items.FindByValue(str1) !=
null
)
{
List2.Items.FindByValue(str1).Selected =
true
;
}
}
}
}
}
}
Thanks,
Jayesh Goyani
0

rms
Top achievements
Rank 1
answered on 16 May 2012, 07:37 PM
Thanks Jayesh,
I have tried you solution. most of it works but I am getting a null reference exception near the below line
Dim strApprovedVlues As String = Convert.ToString(Item.GetDataKeyValue("FailReason"))
Item is declare as
Dim Item As GridDataItem = TryCast(e.Item, GridDataItem)
I have also tried this
Dim strApprovedVlues As String = Item("FailReason").Text
FailReason is a column in my grid.
I thought may be this is because this code is in ItemBound event so i changed it to the RadGrid1_ItemCommand event. in this atleast there is no error but desired functionality is not working.
0

rms
Top achievements
Rank 1
answered on 16 May 2012, 08:40 PM
Also I wanted the mention that I did add
Thanks.
<
MasterTableView
DataKeyNames
=
"FailReason"
>
0
Accepted

Jayesh Goyani
Top achievements
Rank 2
answered on 17 May 2012, 07:26 AM
Hello,
Thanks,
Jayesh Goyani
protected
void
RadGrid1_ItemDataBound(
object
sender, GridItemEventArgs e)
{
if
(e.Item
is
GridDataItem)
{
GridDataItem item = e.Item
as
GridDataItem;
string
strFailReason = item.GetDataKeyValue(
"FailReason"
).ToString();
}
Thanks,
Jayesh Goyani
0

rms
Top achievements
Rank 1
answered on 17 May 2012, 03:38 PM
But ofcourse. why din't I think of it?
Thanks a lot!
Thanks a lot!