如果选中了gridview中的复选框,则文本框将在gridview中可见,否则不可见 [英] if checkbox in gridview is checked then textbox will visible in gridview else invisible
本文介绍了如果选中了gridview中的复选框,则文本框将在gridview中可见,否则不可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
亲爱的
我在gridview中添加了templatefield复选框列和
templatefield文本框列.
如果选中了复选框,则
tetxbox将可见
其他
文本框将不可见
我如何在asp.net中做到这一点
在此先感谢
请给我重播
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
推荐答案
您可以尝试这种方式
创建一个oncheckedchange事件,并在事件引发时(当您选中/取消选中该复选框时)具有可见/不可见选项
我是在gridview的EditItemTempate中完成此操作的,并且有效.也许您可以在ItemTemplate中尝试一下.
问候
Naina
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
您可以使用模板字段或任何bount字段,然后使用JS来显示或隐藏文本框
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">
<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>
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
您也可以使用style.visibility ="hidden"标签代替style.display
如果这对您有帮助,请标记为解决方案
you can use style.visibility="hidden" tag also in place of style.display
if this will help you then please mark as solution
您可以尝试此解决方案...
< asp:gridview id ="GridView1" runat ="server" xmlns:asp =#unknown">
<列> < 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 =服务器""/>
</ItemTemplate>
</asp:TemplateField>
</列>
</asp:GridView>
0n .cs使用此....
foreach(GridView1.Rows中的GridViewRow行)
{
checkBox chkadd =(CheckBox)row.FindControl("chkAdd");
TextBox txtf =(Button)row.FindControl("btngrd");
如果(chkadd.Checked == true)
{txtf.visible = true;}
如果(chkadd.Checked == false)
{
txtf.Visible = false;
}
如果您不想使用JS,那么您可以尝试使用它..
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..
这篇关于如果选中了gridview中的复选框,则文本框将在gridview中可见,否则不可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文