I have a Date Textbox in each row of a Grid View. As the users must not be allowed to put their own values in the text box, we have set the property as ReadOnly="true". And provided a calender java-script plug-in which sets the Textbox value. Now when I am trying to access the date Textbox on save click, the Textbox value is not persisted.
I knew about this issue and resolution for this too. We need to set the readonly attribute on server side to resolve this issue. But my biggest concern here is, I have placed the Textbox inside the Template field of Grid view. So I need to loop through each row of the Grid view, then get the reference to the date Textbox and then set the readonly attribute to readonly. Looks very cumbersome. Could anybody suggest other alternatives or work arounds.
Code as Below
<asp:GridView ID="gv_sample" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td>
<asp:TextBox runat="server" ID="txtByWhen" ReadOnly="true" CssClass="inputbox" Text='<%#Eval("ByWhen") %>'></asp:TextBox>
</td>
<td style="padding-left: 2px;">
<img src="../Images/dateico.gif" alt="Select a date" title="Select a date"
onclick="JavaScript:return showCalendar('<%#((GridViewRow)Container).FindControl("txtByWhen").ClientID %>','dd/mm/y');" />
</td>
</tr>
</table>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>