JavaScript
function callonclick(obj)
{
var sdt = obj.split("_");
var chkDeny=document.getElementById('ctl00_ContentPlaceHolder1_gv_'+sdt[3]+'_chkDeny');
var txtReason=document.getElementById('ctl00_ContentPlaceHolder1_gv_'+sdt[3]+'_txtReason');
if(chkDeny.checked)
{
txtReason.value="";
txtReason.disabled =false;
}
else
{
txtReason.value="Enter Reason";
txtReason.disabled =true;
}
}
On Aspx page
<asp:TemplateField HeaderText="Deny">
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
</EditItemTemplate>
<ItemStyle HorizontalAlign="Center" />
<ItemTemplate>
<asp:CheckBox ID="chkDeny" runat="server" onclick="callonclick(this.id);" />
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" Width="30px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Reason">
<EditItemTemplate>
<asp:TextBox ID="txtsan" runat="server" TextMode="MultiLine" Width="80px"></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<table>
<tr>
<td valign="top">
</td>
<td>
<asp:TextBox ID="txtReason" runat="server" Height="40px" TextMode="MultiLine" Width="250px" Enabled="false">Enter Reason</asp:TextBox></td>
</tr>
</table>
<span style="font-size: 7pt"></span>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
==========================
Nother way Using cs code..
javascript
function StatusGridTextBox(txtReason)
{
document.getElementById(txtReason).disabled = !document.getElementById(txtReason).disabled;
}
on cs code
protected void gv_RowDataBound(object sender, GridViewRowEventArgs e)
{
if ((e.Row.RowType == DataControlRowType.DataRow))
{
((CheckBox)e.Row.FindControl("chkDeny")).Attributes.Add("onclick", "javascript:StatusGridTextBox('" + ((TextBox)e.Row.FindControl("txtReason")).ClientID + "')");
}
}
Thanks & Regards
Santosh
Pretty interesting post! Thanks it was interesting. into a link
ReplyDeleteEnabling a textbox in a gridview on click involves client-side scripting or server-side code.
ReplyDeleteSecure VPN Using JavaScript or jQuery can toggle textbox visibility, enhancing user interaction.