Click here to Skip to main content
14,635,966 members
Rate this:
Please Sign up or sign in to vote.
See more:

I have gridview in which i added a templatefield checkbox column and
a templatefield textbox column.

if checkbox is checked then
tetxbox will be visible
textbox will be invisible

how can i do this in

Thanks in advance

Please give me replay
And what's the problem?
Rate this:
Please Sign up or sign in to vote.

Solution 1

You can try this way

create an event oncheckedchange and have the visible/invisibility option when the event raises(when you check/uncheck the checkbox)

I did this in EditItemTempate in gridview and it worked. May be you can give a try in ItemTemplate.

Rate this:
Please Sign up or sign in to vote.

Solution 2

You can use template field or any bount field and then us JS to display or hide textbox

<asp:gridview id="GridView1" runat="server" xmlns:asp="#unknown">
        <asp:checkbox id="chk" runat="server" onclick="cknunck(this)" />
        <asp:textbox id="tbx" runat="server" style="display:none;"></asp:textbox>

 function cknunck(ck)
            var dis="none";

// nextSibling use to access next element after current element
// if you use bound field then you can use 
// ch.parentElement.nextSibling.children[0] 
// if text box is in next cell of table

you can use style.visibility="hidden" tag also in place of style.display

if this will help you then please mark as solution
Rate this:
Please Sign up or sign in to vote.

Solution 3

You Can Try This one......

<asp:gridview id="GridView1" runat="server" xmlns:asp="#unknown">
<columns> <ItemTemplate>
<asp:CheckBox ID ="chkAdd" AutoPostBack="true" runat="server" oncheckedchanged="chkAdd_CheckedChanged" Enabled="True" />
<asp:TextBox ID="Txtgrd" Visible="false" runat ="server" " />

0n .cs Use this....
foreach (GridViewRow row in GridView1.Rows)
checkBox chkadd = (CheckBox)row.FindControl("chkAdd");
TextBox txtf = (Button)row.FindControl("btngrd");
if (chkadd.Checked == true)
if (chkadd.Checked == false)
txtf.Visible = false;

if U don't want use JS then u sholud try this one..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100