Santaji Garwe
Top achievements
Rank 1
Santaji Garwe
asked on 09 Jul 2008, 05:45 AM
hi
in my grid i have a detail table in which data is binded from a business object in code behind .What i want do is that there are two columns which are not visible but depending on there values (which will be either true or false) that particular row should have edit allowed if both the columns in that particular row are true
in my grid i have a detail table in which data is binded from a business object in code behind .What i want do is that there are two columns which are not visible but depending on there values (which will be either true or false) that particular row should have edit allowed if both the columns in that particular row are true
3 Answers, 1 is accepted
0
Shinu
Top achievements
Rank 2
answered on 09 Jul 2008, 08:02 AM
Hi Santaji,
Set the FieldName of the column which is not visible as the DataKeyNames in the aspx and Try the following code snippet to achieve the desired scenario.
ASPX:
CS:
Thanks
Princy.
Set the FieldName of the column which is not visible as the DataKeyNames in the aspx and Try the following code snippet to achieve the desired scenario.
ASPX:
<DetailTables> |
<telerik:GridTableView runat="server" Name="Detail" DataKeyNames="CheckCol1,CheckCol2" DataSourceID="SqlDataSource2" > |
<Columns> |
<telerik:GridBoundColumn DataField="ValueCol" HeaderText="ValueCol" SortExpression="ValueCol" |
UniqueName="ValueCol" ></telerik:GridBoundColumn> |
<telerik:GridBoundColumn DataField="CheckCol1" HeaderText="CheckCol1" Visible="false" SortExpression="CheckCol1" |
UniqueName="CheckCol1" ></telerik:GridBoundColumn> |
<telerik:GridBoundColumn DataField="CheckCol2" HeaderText="CheckCol2" Visible="false" SortExpression="CheckCol2" |
UniqueName="CheckCol2" ></telerik:GridBoundColumn> |
<telerik:GridEditCommandColumn></telerik:GridEditCommandColumn> |
</Columns> |
</telerik:GridTableView> |
</DetailTables> |
CS:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) |
{ |
if ((e.Item is GridDataItem) && (e.Item.OwnerTableView.Name == "Detail")) |
{ |
GridDataItem item = (GridDataItem)e.Item; |
string strKey1 = item.GetDataKeyValue("CheckCol1").ToString(); |
string strKey2 = item.GetDataKeyValue("CheckCol2").ToString(); |
if ((strKey1 == "True") && (strKey2 == "True")) |
{ |
item.Edit = true; |
} |
} |
} |
Thanks
Princy.
0
Brent
Top achievements
Rank 1
answered on 14 Aug 2009, 12:57 AM
I have a similar requirement, but it differs in that editing is "InPlace", and based upon a row-level data condition, certain fields will be read-only, while the rest of the row remains editable.
ex:
Col1 Col2 Col3 Col4
-------------------------------------
1 open edit edit
2 locked edit read-only
3 open edit edit
4 locked edit read-only
Is there a way to achieve this with server side code in ItemCreated or ItemDataBound?
Thanks,
Brent
(version 2009.2.701.35)
0
Princy
Top achievements
Rank 2
answered on 14 Aug 2009, 06:11 AM
Hi Brent,
Try setting 'COl2' as the DataKeyName and then in the ItemCreated event you may try the following code logic to achieve the desired scenario.
CS:
Best Regards
Princy
Try setting 'COl2' as the DataKeyName and then in the ItemCreated event you may try the following code logic to achieve the desired scenario.
CS:
protected void RadGrid2_ItemCreated(object sender, GridItemEventArgs e) |
{ |
if ((e.Item is GridEditableItem) && (e.Item.IsInEditMode)) |
{ |
GridEditableItem item = (GridEditableItem)e.Item; |
string strCondition = item.GetDataKeyValue("Col2").ToString(); |
if (strCondition == "locked") |
{ |
TextBox txtbx = (TextBox)item["Col4"].Controls[0]; |
txtbx.Visible = false; |
} |
} |
} |
Best Regards
Princy