如何清除javascript中包含gridview行编辑值的文本框
我有以下ASP控件:文本框、gridview、更新按钮和重置按钮 当我单击gridview行的行编辑按钮时,它将填充文本框中的相应值 我的问题是,当我单击reset按钮时,它不会清除gridview行中的textbox值如何清除javascript中包含gridview行编辑值的文本框,javascript,asp.net,asp.net-3.5,asp.net-4.0,Javascript,Asp.net,Asp.net 3.5,Asp.net 4.0,我有以下ASP控件:文本框、gridview、更新按钮和重置按钮 当我单击gridview行的行编辑按钮时,它将填充文本框中的相应值 我的问题是,当我单击reset按钮时,它不会清除gridview行中的textbox值 function btnReset_onclick() { document.getElementById("<%= txtDescription.ClientID %>").value = ""; } protected void GridViewExpe
function btnReset_onclick() {
document.getElementById("<%= txtDescription.ClientID %>").value = "";
}
protected void GridViewExpenses_RowEditing(object sender, GridViewEditEventArgs e)
{
lblExpenseDesc = GridViewExpenses.Rows[e.NewEditIndex].FindControl("lblDescription") as Label;
txtDescription.Text = lblExpenseDesc.Text;
}
函数btnReset\u onclick(){
document.getElementById(“”.value=“”;
}
受保护的无效GridViewEditEventArgs\u行编辑(对象发送方,GridViewEditEventArgs e)
{
lblExpenseDesc=GridViewExpenses.Rows[e.NewEditIndex].FindControl(“lblDescription”)作为标签;
txtDescription.Text=lblExpenseDesc.Text;
}
如何清除文本字段?更新: 删除网格的默认编辑按钮(删除CommandField的ShowEditButton=“True”),并在另一个项目模板中添加一个链接按钮。还将编辑链接按钮的CommandName属性设置为edit(这将有助于编辑按钮作为网格的默认编辑)。然后调用编辑链接按钮的OnClientClick事件上的javascript,并在那里执行逻辑。另外,放置另外两个用于更新和取消的链接按钮,应放置在EditItemTemplate中,CommandName属性,每个按钮应相应设置为更新和取消 请参阅下面的代码以查看实现 Aspx组
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" OnRowCancelingEdit="GridView1_RowCancelingEdit"
OnRowUpdating="GridView1_RowUpdating" OnRowEditing="GridView1_RowEditing">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<%# Eval("sample1")%>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtValue" runat="server"></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="lnkBtnEdit" runat="server" Text="Edit" CommandName="edit" OnClientClick="return ClearText(this.id)"></asp:LinkButton>
</ItemTemplate>
<EditItemTemplate>
<asp:LinkButton ID="lnkBtnUpdate" runat="server" Text="Update" CommandName="update"></asp:LinkButton>
<asp:LinkButton ID="lnkBtnCancel" runat="server" Text="Cancel" CommandName="cancel"></asp:LinkButton>
</EditItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
希望这能帮助您……
<script type="text/javascript">
function clearTextBox() {
document.getElementById('<%= txtTest.ClientID %>').value = "";
}
</script>
<asp:TextBox ID="txtTest" runat="server" Text="blah blah blah" />
<input type="button" value="Clear" onclick="clearTextBox()" />
函数clearTextBox(){
document.getElementById(“”).value=“”;
}
这对我来说很有用…@Kunal Sobti,我猜您正在使用网格视图的默认编辑按钮。如果是这样,单击编辑按钮将显示更新按钮和取消按钮。我想你需要点击编辑按钮调用javascript函数。为此,您必须使用自定义按钮而不是默认的编辑按钮…您实际使用的是ASP.NET 3.5或4.0,还是两者都使用?重置按钮在哪里?是网格编辑元素表单的标准“取消”按钮吗?或者您的网格中有EditTemplate,并且您在那里有自己的asp:按钮吗?或者按钮完全写在网格之外?老实说,我们需要查看一些您的aspx代码来帮助您。否则,这就像问别人如何修理你的车,而不告诉他们它是什么车。。。
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1;
populate();
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
//do update logic here
GridView1.EditIndex = -1;
populate();
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
populate();
}
<script type="text/javascript">
function clearTextBox() {
document.getElementById('<%= txtTest.ClientID %>').value = "";
}
</script>
<asp:TextBox ID="txtTest" runat="server" Text="blah blah blah" />
<input type="button" value="Clear" onclick="clearTextBox()" />