Click here to Skip to main content
16,004,782 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a gridview with textbox . I want to readonly true to textbox using jquery



My gridview code


XML
<asp:GridView ID="gvFeeStructure" CssClass="mGrid" runat="server"
AutoGenerateColumns="False" onrowdatabound="gvFeeStructure_RowDataBound" Width="450px" >
<Columns>
<asp:TemplateField HeaderText="Ins. No">
<ItemTemplate>
<asp:Label ID="lblInsNo" runat="server" Text='<%# Eval("insNo") %>'></asp:Label>
</ItemTemplate>

</asp:TemplateField>
<asp:TemplateField HeaderText="Ins.&nbsp;Date">

<ItemTemplate>
<asp:Label Id="lblInsDate" runat="server" Text='<%# Eval("insPaidDate","{0:dd-MMM-yyyy}") %>' ></asp:Label>
<asp:TextBox ID="txtInsDate" runat="server" Text='<%# Eval("insPaidDate","{0:dd-MMM-yyyy}") %>'
Width="80px" CssClass="fundtext readonly" ></asp:TextBox>
<asp:ImageButton ID="imgbtnDatePicker" CssClass="datepickericon" AlternateText="Select Date" ToolTip="Select Date" runat="server" ImageUrl="~/Images/calendar_icon_small.png" />
<asp:CalendarExtender ID="calendarAdmissionDate" runat="server" CssClass="calendarstyle" DefaultView="Months" Format="dd-MMM-yyyy" TargetControlID="txtInsDate" PopupButtonID="imgbtnDatePicker">
</asp:CalendarExtender>

<asp:RequiredFieldValidator ID="reqInsDate" ValidationGroup="date" CssClass="error" ControlToValidate="txtInsDate" runat="server">*</asp:RequiredFieldValidator>
<%-- <asp:CompareValidator id="cvDate" runat="server" cultureinvariantvalues="true" display="none" enableclientscript="true"
ControlToValidate="txtInsDate" ErrorMessage="installment date must be greater than current date" type="Date" setfocusonerror="true" Operator="GreaterThanEqual" text="installment date must be greater than current date" />--%>
<asp:HiddenField ID="hfId" runat="server" Value='<%# Eval("srno") %>' />
</ItemTemplate>
<ItemStyle Width="150px" Font-Bold="True" ForeColor="Black" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Ins.&nbsp;Amount">
<ItemTemplate>
<asp:Label Id="lblInsAmount" runat="server" Text='<%# Eval("InsAmount") %>' ></asp:Label>
</ItemTemplate>
</asp:TemplateField>

<asp:TemplateField HeaderText="Paid&nbsp;Amount">
<ItemTemplate>
<asp:Label Id="lblInspaidAmount" runat="server" Text='<%# Eval("insPaidAmount") %>' ></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Balance">
<ItemTemplate>
<asp:Label Id="lblBalance" runat="server" Text='<%# Eval("balance") %>' ></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EmptyDataTemplate>
Sorry no record exist.
</EmptyDataTemplate>
</asp:GridView>





My jquery code



C#
<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$('.readonly').change(function () {
$(this).attr('readonly', true);
});

});



</script>


but this code do not work
Posted
Updated 22-May-13 22:41pm
v2
Comments
Thanks7872 23-May-13 4:44am    
Why you want to use JQuery for this? You can simply add ReadOnly="true" attribute to your textbox.
ashok luhach 23-May-13 5:41am    
Becouse there are a CalenderExtender control and when i select date from CalenderExtender this date not update in my database, it take old value so i can not use readonly property
ashok luhach 23-May-13 6:44am    
this post not related to my question
vijay__p 23-May-13 5:30am    
Just try $(this).attr('readonly', 'readonly');

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