更新时间:2023-01-11 12:25:34
您可以尝试这种方式
创建一个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..