Click here to Skip to main content
15,895,777 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Dear

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
else
textbox will be invisible

how can i do this in asp.net

Thanks in advance

Please give me replay
Posted
Comments
Sergey Alexandrovich Kryukov 16-Jan-12 1:39am    
And what's the problem?
--SA

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.

Regards
Naina
 
Share this answer
 
You can use template field or any bount field and then us JS to display or hide textbox

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


JavaScript
 function cknunck(ck)
        {
            var dis="none";
            if(ck.checked)
                dis="";
            ck.nextSibling.style.display=dis;

        }
// 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
 
Share this answer
 
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" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:TextBox ID="Txtgrd" Visible="false" runat ="server" " />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>


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)
{txtf.visible=true;}
if (chkadd.Checked == false)
{
txtf.Visible = false;
}

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

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