6 Answers, 1 is accepted
0
Shinu
Top achievements
Rank 2
answered on 01 Mar 2012, 05:25 AM
Hello,
Try the following code.
C#:
-Shinu.
Try the following code.
C#:
protected
void
grid_ItemDataBound(
object
sender, GridItemEventArgs e)
{
if
(e.Item
is
GridEditableItem && e.Item.IsInEditMode)
{
GridEditableItem item = (GridEditableItem)e.Item;
RadioButtonList list = (RadioButtonList)item.FindControl(
"RadioButtonList1"
);
}
}
-Shinu.
0
Snehalata
Top achievements
Rank 1
answered on 02 Mar 2012, 05:05 AM
Thank you so much Shinu.It's working now.
If TypeOf e.Item Is GridEditableItem AndAlso e.Item.OwnerTableView.EditMode And TypeOf e.Item Is GridEditFormItem Then
If (TypeOf e.Item Is GridEditFormItem AndAlso e.Item.IsInEditMode) Then
Dim editFormItem As GridEditFormItem = CType(e.Item, GridEditFormItem)
radb = e.Item.FindControl("RadBtnLst")
Dim dataItem As GridEditFormItem = CType(e.Item, GridEditFormItem)
Dim fieldValue As String = (dataItem("deptwacc").Text)
'If fieldValue <> "" Then
If fieldValue = "Y" Then
radb.SelectedValue = "Yes"
ElseIf fieldValue = "N" Then
radb.SelectedValue = "No"
End If
End If
End If
If TypeOf e.Item Is GridEditableItem AndAlso e.Item.OwnerTableView.EditMode And TypeOf e.Item Is GridEditFormItem Then
If (TypeOf e.Item Is GridEditFormItem AndAlso e.Item.IsInEditMode) Then
Dim editFormItem As GridEditFormItem = CType(e.Item, GridEditFormItem)
radb = e.Item.FindControl("RadBtnLst")
Dim dataItem As GridEditFormItem = CType(e.Item, GridEditFormItem)
Dim fieldValue As String = (dataItem("deptwacc").Text)
'If fieldValue <> "" Then
If fieldValue = "Y" Then
radb.SelectedValue = "Yes"
ElseIf fieldValue = "N" Then
radb.SelectedValue = "No"
End If
End If
End If
0
Snehalata
Top achievements
Rank 1
answered on 02 Mar 2012, 05:09 AM
Now I want to put javascript validation to the radiobuttonlist inside radgrid. I am unable to fetch it and to give it focus.Please help me out.
0
Shinu
Top achievements
Rank 2
answered on 02 Mar 2012, 05:40 AM
Hello,
Try the following javascript.
JS:
-Shinu.
Try the following javascript.
JS:
function
Click()
{
var
grid = $find(
"<%=RadGrid1.ClientID %>"
);
var
masterTable = grid.get_masterTableView();
var
rows = masterTable.get_dataItems();
for
(
var
i = 0; i < rows.length; i++)
{
var
rbtn = rows[i].findElement(
'RadioButtonList1'
);
}
}
-Shinu.
0
Snehalata
Top achievements
Rank 1
answered on 02 Mar 2012, 10:34 AM
Hi Shinu,
it's not working. What you have given is to search the control radiobuttonlist for every row. But what I am using is radgrid menu control. I want to validate whether radiobuttonlist is selected or not in edit/insert mode in radgrid.I am giving you the sample code what i am using now.
Grid Design
<telerik:RadGrid ID="CategoryGrid" runat="server" AllowMultiRowSelection="False"
AllowPaging="True" AllowSorting="True" AutoGenerateColumns="false"
ShowStatusBar="true" Skin="Outlook">
<headercontextmenu cssclass="GridContextMenu GridContextMenu_Default">
</headercontextmenu>
<PagerStyle AlwaysVisible="true"/>
<mastertableview allowmulticolumnsorting="True" commanditemdisplay="Top"
datakeynames="CATCOD" name="Category">
<Columns>
<telerik:GridEditCommandColumn HeaderText="Edit" UniqueName="EditCommandColumn" ButtonType="ImageButton">
<ItemStyle Width="50px" />
</telerik:GridEditCommandColumn>
<telerik:GridBoundColumn DataField="CATCOD"
HeaderButtonType="TextButton" HeaderText="CATEGORY CODE"
SortExpression="CATCOD" UniqueName="CATCOD">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="DESCRIPTION"
HeaderButtonType="TextButton" HeaderText="DESCRIPTION"
SortExpression="DESCRIPTION" UniqueName="DESCRIPTION">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="per"
HeaderButtonType="TextButton" HeaderText="PERCENTAGE"
SortExpression="per" UniqueName="per">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="deptwacc"
HeaderButtonType="TextButton" HeaderText="DEPT WISE ACCOMODATION"
SortExpression="deptwacc" UniqueName="deptwacc">
</telerik:GridBoundColumn>
<telerik:GridButtonColumn ButtonType="ImageButton" CommandName="Delete"
ConfirmText="Delete this Category ?" Text="Delete" UniqueName="DeleteColumn1">
<HeaderStyle Width="20px" />
<ItemStyle CssClass="MyImageButton" HorizontalAlign="Center" />
</telerik:GridButtonColumn>
</Columns>
<editformsettings editformtype="Template">
<formtemplate>
<table id="tblCategoryMaster" border="1" cellpadding="1" cellspacing="2"
rules="none" style="border-collapse: collapse; background: white;" width="100%">
<tr class="EditFormHeader">
<td colspan="2" style="font-size: small; font-family: Verdana;color:Maroon">
<b>CategoryDetail</b>
</td>
</tr>
<tr>
<td>
<table id="Table3" border="0" cellpadding="1" cellspacing="1" class="module"
width="250">
<tr>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td >
<asp:Label ID="label2" Text="Category Code:" runat="server" Font-Names="verdana" Font-Size="8.5pt"
ForeColor="Maroon"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtCatCod" runat="server" Font-Names="verdana" Font-Size="8.5pt"
MaxLength="50" ReadOnly="true" TabIndex="1" Text='<%# Bind("CATCOD") %>'>
</asp:TextBox>
</td>
</tr>
<tr>
<td >
<asp:Label ID="label1" Text="Description:" runat="server" Font-Names="verdana" Font-Size="8.5pt"
ForeColor="Maroon"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtCatDesc" runat="server" Font-Names="verdana"
Font-Size="8.5pt" MaxLength="50" onkeypress=" return valid(event,50)"
TabIndex="2" Text='<%# Bind("DESCRIPTION") %>'>
</asp:TextBox>
<asp:RequiredFieldValidator ID="RFVCatDesc" runat="server"
ControlToValidate="txtCatDesc" ErrorMessage="Enter Description."></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td >
<asp:Label ID="label4" Text="Percentage:" runat="server" Font-Names="verdana" Font-Size="8.5pt"
ForeColor="Maroon"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtperc" runat="server" Font-Names="verdana"
Font-Size="8.5pt" MaxLength="50" TabIndex="3" Text='<%# Bind("per") %>'>
</asp:TextBox>%
<%--<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="txtCatDesc" ErrorMessage="Enter Percentage."></asp:RequiredFieldValidator>--%>
</td>
</tr>
<tr>
<td >
<asp:Label ID="label3" Text="Dept Wise Accomodation:" runat="server" Font-Names="verdana" Font-Size="8.5pt"
ForeColor="Maroon"></asp:Label>
</td>
<td>
<asp:RadioButtonList ID="RadBtnLst" runat="server" TabIndex="4" Font-Names="verdana"
Font-Size="8.5pt" RepeatDirection="Horizontal" DataValueField='<%# Bind("deptwacc") %>' AutoPostBack="True">
<asp:ListItem Text="Yes" onclick="validateButtonList(this);"/>
<asp:ListItem Text="No" onclick="validateButtonList(this);"/>
</asp:RadioButtonList>
<%--<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ControlToValidate="RadBtnLst" ErrorMessage="Select Dept wise accomodation."></asp:RequiredFieldValidator>--%>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td align="right" colspan="2">
<asp:Button ID="btnUpdate3" runat="server" OnClientClick="return ValidName()"
CommandName='<%# IIf((TypeOf(Container) is GridEditFormInsertItem), "PerformInsert", "Update")%>' Style="color: White; background-color: SteelBlue; font-family: Verdana; font-size: 8pt;
width: 87px;"
Text='<%# IIf((TypeOf(Container) is GridEditFormInsertItem), "Insert", "Update") %>'/>
<asp:Button ID="btnCancel3" runat="server" CausesValidation="False"
CommandName="Cancel" Style="color: White; background-color: SteelBlue; font-family: Verdana;
font-size: 8pt; width: 87px;" Text="Cancel" />
</td>
</tr>
</table>
</formtemplate>
</editformsettings>
</mastertableview>
</telerik:RadGrid>
Javascript code under <div>
<script type="text/javascript">
function GetGridServerElement(serverID, tagName) {
if (!tagName)
tagName = "*"; //* means all elements
var grid = document.getElementById("<%=CategoryGrid.ClientID %>");
var elements = grid.getElementsByTagName(tagName);
for (var i = 0; i < elements.length; i++) {
var element = elements[i];
if (element.id.indexOf(serverID) >= 0)
return element;
}
}
function ValidName() {
var serverID = "txtCatDesc";
var tagName = "*"; //dropdowns render as <select> elements
//var dropDown = GetRegisteredServerElement(serverID);
var txtCatDesc = GetGridServerElement(serverID, tagName);
if (txtCatDesc.value == '') {
alert('Enter Description');
txtCatDesc.focus();
return false;
}
validateUpdate()
}
</script>
<script type="text/javascript">
function validateUpdate() {
if (status !="Yes" && status !="No") {
alert('Select Dept Wise Accomodation.');
//status.focus();
return false;
} else { return false; }
}
var status;
function validateButtonList(radioButtonListObj) {
status = radioButtonListObj.value;
}
</script>
Best regards,
Sneha.
it's not working. What you have given is to search the control radiobuttonlist for every row. But what I am using is radgrid menu control. I want to validate whether radiobuttonlist is selected or not in edit/insert mode in radgrid.I am giving you the sample code what i am using now.
Grid Design
<telerik:RadGrid ID="CategoryGrid" runat="server" AllowMultiRowSelection="False"
AllowPaging="True" AllowSorting="True" AutoGenerateColumns="false"
ShowStatusBar="true" Skin="Outlook">
<headercontextmenu cssclass="GridContextMenu GridContextMenu_Default">
</headercontextmenu>
<PagerStyle AlwaysVisible="true"/>
<mastertableview allowmulticolumnsorting="True" commanditemdisplay="Top"
datakeynames="CATCOD" name="Category">
<Columns>
<telerik:GridEditCommandColumn HeaderText="Edit" UniqueName="EditCommandColumn" ButtonType="ImageButton">
<ItemStyle Width="50px" />
</telerik:GridEditCommandColumn>
<telerik:GridBoundColumn DataField="CATCOD"
HeaderButtonType="TextButton" HeaderText="CATEGORY CODE"
SortExpression="CATCOD" UniqueName="CATCOD">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="DESCRIPTION"
HeaderButtonType="TextButton" HeaderText="DESCRIPTION"
SortExpression="DESCRIPTION" UniqueName="DESCRIPTION">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="per"
HeaderButtonType="TextButton" HeaderText="PERCENTAGE"
SortExpression="per" UniqueName="per">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="deptwacc"
HeaderButtonType="TextButton" HeaderText="DEPT WISE ACCOMODATION"
SortExpression="deptwacc" UniqueName="deptwacc">
</telerik:GridBoundColumn>
<telerik:GridButtonColumn ButtonType="ImageButton" CommandName="Delete"
ConfirmText="Delete this Category ?" Text="Delete" UniqueName="DeleteColumn1">
<HeaderStyle Width="20px" />
<ItemStyle CssClass="MyImageButton" HorizontalAlign="Center" />
</telerik:GridButtonColumn>
</Columns>
<editformsettings editformtype="Template">
<formtemplate>
<table id="tblCategoryMaster" border="1" cellpadding="1" cellspacing="2"
rules="none" style="border-collapse: collapse; background: white;" width="100%">
<tr class="EditFormHeader">
<td colspan="2" style="font-size: small; font-family: Verdana;color:Maroon">
<b>CategoryDetail</b>
</td>
</tr>
<tr>
<td>
<table id="Table3" border="0" cellpadding="1" cellspacing="1" class="module"
width="250">
<tr>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td >
<asp:Label ID="label2" Text="Category Code:" runat="server" Font-Names="verdana" Font-Size="8.5pt"
ForeColor="Maroon"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtCatCod" runat="server" Font-Names="verdana" Font-Size="8.5pt"
MaxLength="50" ReadOnly="true" TabIndex="1" Text='<%# Bind("CATCOD") %>'>
</asp:TextBox>
</td>
</tr>
<tr>
<td >
<asp:Label ID="label1" Text="Description:" runat="server" Font-Names="verdana" Font-Size="8.5pt"
ForeColor="Maroon"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtCatDesc" runat="server" Font-Names="verdana"
Font-Size="8.5pt" MaxLength="50" onkeypress=" return valid(event,50)"
TabIndex="2" Text='<%# Bind("DESCRIPTION") %>'>
</asp:TextBox>
<asp:RequiredFieldValidator ID="RFVCatDesc" runat="server"
ControlToValidate="txtCatDesc" ErrorMessage="Enter Description."></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td >
<asp:Label ID="label4" Text="Percentage:" runat="server" Font-Names="verdana" Font-Size="8.5pt"
ForeColor="Maroon"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtperc" runat="server" Font-Names="verdana"
Font-Size="8.5pt" MaxLength="50" TabIndex="3" Text='<%# Bind("per") %>'>
</asp:TextBox>%
<%--<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="txtCatDesc" ErrorMessage="Enter Percentage."></asp:RequiredFieldValidator>--%>
</td>
</tr>
<tr>
<td >
<asp:Label ID="label3" Text="Dept Wise Accomodation:" runat="server" Font-Names="verdana" Font-Size="8.5pt"
ForeColor="Maroon"></asp:Label>
</td>
<td>
<asp:RadioButtonList ID="RadBtnLst" runat="server" TabIndex="4" Font-Names="verdana"
Font-Size="8.5pt" RepeatDirection="Horizontal" DataValueField='<%# Bind("deptwacc") %>' AutoPostBack="True">
<asp:ListItem Text="Yes" onclick="validateButtonList(this);"/>
<asp:ListItem Text="No" onclick="validateButtonList(this);"/>
</asp:RadioButtonList>
<%--<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ControlToValidate="RadBtnLst" ErrorMessage="Select Dept wise accomodation."></asp:RequiredFieldValidator>--%>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td align="right" colspan="2">
<asp:Button ID="btnUpdate3" runat="server" OnClientClick="return ValidName()"
CommandName='<%# IIf((TypeOf(Container) is GridEditFormInsertItem), "PerformInsert", "Update")%>' Style="color: White; background-color: SteelBlue; font-family: Verdana; font-size: 8pt;
width: 87px;"
Text='<%# IIf((TypeOf(Container) is GridEditFormInsertItem), "Insert", "Update") %>'/>
<asp:Button ID="btnCancel3" runat="server" CausesValidation="False"
CommandName="Cancel" Style="color: White; background-color: SteelBlue; font-family: Verdana;
font-size: 8pt; width: 87px;" Text="Cancel" />
</td>
</tr>
</table>
</formtemplate>
</editformsettings>
</mastertableview>
</telerik:RadGrid>
Javascript code under <div>
<script type="text/javascript">
function GetGridServerElement(serverID, tagName) {
if (!tagName)
tagName = "*"; //* means all elements
var grid = document.getElementById("<%=CategoryGrid.ClientID %>");
var elements = grid.getElementsByTagName(tagName);
for (var i = 0; i < elements.length; i++) {
var element = elements[i];
if (element.id.indexOf(serverID) >= 0)
return element;
}
}
function ValidName() {
var serverID = "txtCatDesc";
var tagName = "*"; //dropdowns render as <select> elements
//var dropDown = GetRegisteredServerElement(serverID);
var txtCatDesc = GetGridServerElement(serverID, tagName);
if (txtCatDesc.value == '') {
alert('Enter Description');
txtCatDesc.focus();
return false;
}
validateUpdate()
}
</script>
<script type="text/javascript">
function validateUpdate() {
if (status !="Yes" && status !="No") {
alert('Select Dept Wise Accomodation.');
//status.focus();
return false;
} else { return false; }
}
var status;
function validateButtonList(radioButtonListObj) {
status = radioButtonListObj.value;
}
</script>
Best regards,
Sneha.
0
Shinu
Top achievements
Rank 2
answered on 05 Mar 2012, 05:53 AM
Hello,
Take a look at the following code library.
Accessing server controls in a grid template on the client
-Shinu.
Take a look at the following code library.
Accessing server controls in a grid template on the client
-Shinu.