如何使用javascript更改按钮单击时所选行的gridview列中的值。 [英] how to change the value in a gridview column for selected row on button click using javascript.?
本文介绍了如何使用javascript更改按钮单击时所选行的gridview列中的值。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用javascript更改按钮点击中所选行的gridview列中的值。
即i想要使用javascript函数给列赋值。
谢谢
Hi,
how to change the value in a gridview column for selected row on button click using javascript.
that is i want to a new value to a column using javascript function.
thanks
推荐答案
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:GridView ID="grd" runat="server" BackColor="White" BorderColor="#CC9966"
BorderStyle="None" BorderWidth="1px" CellPadding="4">
<FooterStyle BackColor="#FFFFCC" ForeColor="#330099" />
<Columns>
<asp:CommandField ButtonType="Button" ShowSelectButton="True" />
</Columns>
<RowStyle BackColor="White" ForeColor="#330099" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="#663399" />
<PagerStyle BackColor="#FFFFCC" ForeColor="#330099" HorizontalAlign="Center" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="#FFFFCC" />
</asp:GridView>
</form>
</body>
</html>
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
DataTable tbl = new DataTable();
tbl.Columns.Add("Name");
tbl.Columns.Add("Title");
tbl.Columns.Add("FullName");
tbl.Rows.Add("DINESH", "TAILOR", "");
tbl.Rows.Add("RAJESH", "TAILOR", "");
grd.RowDataBound += new GridViewRowEventHandler(grd_RowDataBound);
grd.DataSource = tbl;
grd.DataBind();
}
void grd_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Button b = (Button)e.Row.Controls[0].Controls[0];
b.Attributes.Add("onClick", "var tr = document.getElementById('" + e.Row.ClientID + "'); tr.cells[3].innerText = tr.cells[1].innerText + ' ' + tr.cells[2].innerText; return false;");
}
}
}
这篇关于如何使用javascript更改按钮单击时所选行的gridview列中的值。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文