asp.net网格视图超链接将值传递给新窗口

时间:2013-06-26 17:03:09

标签: asp.net gridview

这些人是我的问题,请帮帮我

我有一个带有超链接字段的gridview我的要求是如果我点击特定行的超链接我需要将该特定行值显示到该页面中的其他页面用户将在此之后编辑记录值如果他点击更新按钮我需要更新该记录值并返回上一个主页。如果我在第一个窗口中点击超级链接新窗口应该打开任何网址工具栏并最小化关闭按钮,如弹出模块化Ajax ModalPopUpExtender但我不能ge那那个请帮助我

填充代码为defalut.aspx

<head runat="server">
<title>PassGridviewRow values </title>
<style type="text/css">
#gvrecords tr.rowHover:hover
{
    background-color:Yellow;
    font-family:Arial;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView runat="server" ID="gvrecords"  AutoGenerateColumns="false" 
HeaderStyle-BackColor="#7779AF" HeaderStyle-ForeColor="White" DataKeyNames="UserId" RowStyle-CssClass="rowHover"> 
<Columns>
<asp:TemplateField  HeaderText="Change Password" >
<ItemTemplate>
<a href ='<%#"UpdateGridviewvalues.aspx?UserId="+DataBinder.Eval(Container.DataItem,"UserId") %>'> <%#Eval("UserName") %>  </a>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="FirstName" HeaderText="FirstName" />
<asp:BoundField DataField="LastName" HeaderText="LastName" />
<asp:BoundField DataField="Email" HeaderText="Email" />
</Columns>
</asp:GridView>
</div>
</form>
</body>
</html>

代码default.aspx.cs代码

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page 
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindGridview();
}
}
protected void BindGridview()
{
SqlConnection con = new SqlConnection("Data Source=.;Integrated Security=SSPI;Initial Catalog=testdb1");
con.Open();
SqlCommand cmd = new SqlCommand("select * from UserDetails", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
cmd.ExecuteNonQuery();
con.Close();        
DataSet ds = new DataSet();
da.Fill(ds);
gvrecords.DataSource = ds;
gvrecords.DataBind();
}
}

这是updategridviewvalues.aspx

<head runat="server">
<title>Update Gridview Row Values</title>
<script type="text/javascript">
function Showalert(username) {
alert(username + ' details updated successfully.');
if (alert) {
window.location = 'Default.aspx';
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr>
<td colspan="2" align="center">
<b> Edit User Details</b>
</td>
</tr>
<tr>
<td>
User Name:
</td>
<td>
<asp:Label ID="lblUsername" runat="server"/>
</td>
</tr>
<tr>
<td>
First Name:
</td>
<td>
<asp:TextBox ID="txtfname" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
Last Name:
</td>
<td>
<asp:TextBox ID="txtlname" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
Email:
</td>
<td>
<asp:TextBox ID="txtemail" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:Button ID="btnUpdate" runat="server" Text="Update" onclick="btnUpdate_Click" />
<asp:Button ID="btnCancel" runat="server" Text="Cancel" onclick="btnCancel_Click"/>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>

我的updategridviewvalues.aspx.cs代码如下

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class UpdateGridviewvalues : System.Web.UI.Page
{
SqlConnection con = new SqlConnection("Data Source=.;Integrated Security=SSPI;Initial Catalog=testdb1");
private int userid=0;
protected void Page_Load(object sender, EventArgs e)
{
userid = Convert.ToInt32(Request.QueryString["UserId"].ToString());
if(!IsPostBack)
{
BindControlvalues();    
}

}

private void BindControlvalues()
{
con.Open();
SqlCommand cmd = new SqlCommand("select * from UserDetails where UserId=" + userid, con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
cmd.ExecuteNonQuery();
con.Close();
DataSet ds = new DataSet();
da.Fill(ds);
lblUsername.Text = ds.Tables[0].Rows[0][1].ToString();
txtfname.Text = ds.Tables[0].Rows[0][2].ToString();
txtlname.Text = ds.Tables[0].Rows[0][3].ToString();
txtemail.Text = ds.Tables[0].Rows[0][4].ToString();
}

protected void btnUpdate_Click(object sender, EventArgs e)
{
con.Open();
SqlCommand cmd = new SqlCommand("update UserDetails set FirstName='" + txtfname.Text + "',LastName='" + txtlname.Text + "',Email='" + txtemail.Text + "' where UserId=" + userid, con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
int result= cmd.ExecuteNonQuery();
con.Close();
if(result==1)
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "ShowSuccess", "javascript:Showalert('"+lblUsername.Text+"')", true);
}
}

protected void btnCancel_Click(object sender, EventArgs e)
{
Response.Redirect("~/Default.aspx");
}
}

我的要求是新窗口应该像弹出窗口一样,有新的窗口,有网址和关闭按钮 我的数据库表是

ColumnName                 DataType
-------------------------------------------
UserId                    Int(set identity property=true)
UserName                 varchar(50)                 
FirstName                varchar(50)
LastName                 varchar(50)
Email                    Varchar(50)

1 个答案:

答案 0 :(得分:1)

jQuery字段中有很多选项:

jQueryUI的dialog

Wijmo的Dialog

SimpleModal

如果您已经使用过jQuery,那么jQueryUI的选项可能非常合适。 Wijmo也兼容jQueryUI /友好(使用相同的主题CSS类名称和模式),所以它也很适合。

所以这取决于你想要什么。非常简单的东西 - 也许是jQueryUI。华丽/漂亮 - SimpleModal。更复杂,但jQueryUI友好 - Wijmo。