如何在单击链接按钮时隐藏文本框控件,其中这两个控件都是网格视图的子控件
How to hide a textbox control when clicking on a linkbutton where these both are child controls to gridview?
我有一个下的网格视图
<asp:GridView ID="dgTask" runat="server" Width="100%"
AutoGenerateColumns="False" onrowdatabound="dgTask_RowDataBound">
<Columns>
<asp:BoundField DataField="TaskID" HeaderText="TaskID" ItemStyle-Width="1%" />
<asp:BoundField DataField="TaskName" HeaderText="Task Name" ItemStyle-HorizontalAlign="left"
ItemStyle-Width="10%" />
<asp:BoundField DataField="PriorityName" HeaderText="Priority" ItemStyle-HorizontalAlign="center"
ItemStyle-Width="10%" />
<asp:BoundField DataField="StatusName" HeaderText="Status" ItemStyle-HorizontalAlign="center"
ItemStyle-Width="10%" />
<asp:TemplateField HeaderText="Edit Task" ItemStyle-Width="10%">
<ItemTemplate>
<asp:LinkButton ID="lnkBtnEdit" runat="Server" Text="Edit" CommandArgument ='<%# Eval("TaskID") %>' />
<asp:TextBox ID="txtId" runat="server"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
现在,我要做的是,在linkButton的点击事件中,我需要隐藏该行的文本框控件。
如何做到这一点?
到目前为止,我已经做了
protected void dgTask_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
LinkButton btnEdit = (LinkButton)e.Row.Cells[4].FindControl("lnkBtnEdit");
btnEdit.Attributes.Add("onclick", "return Test();");
}
}
感谢
您正走在正确的道路上,只需在调用javascript函数时进行一些小的更改,然后添加如下所示的javascript函数。
protected void dgTask_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
LinkButton btnEdit = (LinkButton)e.Row.Cells[4].FindControl("lnkBtnEdit");
TextBox txtId = (TextBox)e.Row.Cells[4].FindControl("txtId");
btnEdit.Attributes.Add("onclick", "return Test("'" + txtId.ClientId + "'");");
}
}
像这样添加Javascript,
function Test(var txtId)
{
var inputtxt = document.getElementById(txtId);
if(inputtxt != null)
{
inputtxt.Attributes.Add("style","display:none;");
}
}
试试这个:
protected void LinkButton1_Click(object sender, EventArgs e)
{
LinkButton b = (LinkButton)sender;
GridViewRow r = (GridViewRow)b.NamingContainer;
((TextBox)(GridView1.Rows[r.RowIndex].Cells[0].FindControl("TextBox1"))).Visible = false;
}
相关文章:
- 使用相同javascript的多个控件
- 具有多个控件的数据视图
- 多个控件的javascript函数调用
- 引导程序转盘隐藏第一个和最后一个控件
- 如何在三个js上更新Trackball控件
- 当表单控件选项具有多个参数时,如何在组合框中填充所选项目
- Three.js具有两个(切换)摄影机的动态观察控件
- 硒找到两个相同的控件
- ASP.NET 自定义控件,两个网格.需要一些建议
- ASP MVC将两个控件绑定到一个字段
- Javascript在onclick上验证两个控件,但如果只有一个控件验证,则不保留值
- 使用jquery的同一页面中的两个用户控件不起作用
- 使用两个选择控件编辑表单,以便在首次启动时进行筛选
- ascx控件两次添加到页面时调用了错误的javascript函数
- 如何在单击链接按钮时隐藏文本框控件,其中这两个控件都是网格视图的子控件
- Google Charts:一组绑定控件>两个基于不同数据表的图表,通过相同的列名/值
- 如何在Google charts仪表板中运行两个查询并显示两个带有控件的图表
- 如何从angular变量中拆分字符串值,并将其设置为两个html控件
- 如何在单个HTML页面中使用两个角pickadate日历控件
- 你能让两个.ascx控件通过javascript相互通信吗?