GridView控件管理用户信息的问题

dongjiajia501 2012-05-04 05:20:10
aspx文件内容:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="dongjiajia.WebForm2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div style="height: 376px; width: 575px" dir="ltr">

<asp:GridView ID="gvmsg" runat="server" AllowPaging="True"
AutoGenerateColumns="False" CellPadding="4" DataKeyNames="username"
ForeColor="#333333" GridLines="None" OnPageIndexChanging="gvmsg_pageindexchanging"
OnRowEditing = "gvmsg_rowediting" OnRowUpdating="gvmsg_rowupdating"
OnRowCancelingEdit="gvmsg_rowcancelingedit" Height="365px" Width="359px"
onselectedindexchanged="gvmsg_SelectedIndexChanged" PageSize="6">
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#507CD1" ForeColor="White" />
<EditRowStyle BackColor="#2461BF" BorderWidth="100px"
HorizontalAlign="Center" />
<AlternatingRowStyle BackColor="White" />
<RowStyle BackColor="#EFF3FB" />
<Columns>
<asp:BoundField DataField ="username" HeaderText="昵称"/>
<asp:BoundField DataField ="sex" HeaderText ="性别"/>
<asp:BoundField DataField ="email" HeaderText="电子邮件"/>
<asp:BoundField DataField ="content" HeaderText="留言内容"/>
<asp:CommandField ShowEditButton="true" HeaderText="修改"/>
<asp:CommandField ShowDeleteButton ="true" HeaderText="删除"/>
</Columns>

</asp:GridView>

<br />

</div>
<p>
 </p>
</form>
</body>
</html>

cs文件内容:
public partial class WebForm2 : System.Web.UI.Page
{
MySqlConnection mycon;

protected void Page_Load(object sender, EventArgs e)
{

string strcon = "server=localhost;user id=root;password=;database=mysql";
mycon = new MySqlConnection(strcon);

if (!IsPostBack)
{
BindGridView();
}

}
protected void BindGridView()
{
this.gvmsg.DataBind();
}
protected void gvmsg_rowediting(object sender, GridViewEditEventArgs e)
{
this.gvmsg.EditIndex = e.NewEditIndex;

BindGridView();
}
protected void gvmsg_rowupdating(object sender, GridViewUpdateEventArgs e)
{
string strsql = "update book set sex=@sex,email=@email,content=@content where username=@username";
MySqlCommand mycmd = new MySqlCommand(strsql, mycon);
mycmd.Parameters.Add(new MySqlParameter("@username",MySqlDbType.VarChar,50));
mycmd.Parameters.Add(new MySqlParameter("@sex", MySqlDbType.VarChar, 50));
mycmd.Parameters.Add(new MySqlParameter("@email", MySqlDbType.VarChar, 50));
mycmd.Parameters.Add(new MySqlParameter("@content", MySqlDbType.VarChar, 50));
string ts="";
mycmd.Parameters["@sex"].Value.ToString()= ts;
TextBox tc = (TextBox)this.gvmsg.Rows[e.RowIndex].Cells[4].FindControl("content");

mycmd.Parameters["@content"].Value.ToString() = tc;
mycmd.Connection.Open();
try
{
mycmd.ExecuteNonQuery();
this.gvmsg.EditIndex = -1;
BindGridView();
}
catch
{

}
}
protected void gvmsg_rowcancelingedit(object sender, GridViewCancelEditEventArgs e)
{
this.gvmsg.EditIndex = -1;
BindGridView();

}
protected void gvmsg_pageindexchanging(object sender, GridViewPageEventArgs e)
{
this.gvmsg.PageIndex = e.NewPageIndex;
BindGridView();
}

protected void gvmsg_SelectedIndexChanged(object sender, EventArgs e)
{

}
}

问题:
运行完成后网页是空白的????
...全文
77 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
wilsonhong 2012-05-07
  • 打赏
  • 举报
回复
protected void BindGridView()
{
this.gvmsg.Source=你的数据源
this.gvmsg.DataBind();
}
tkss 2012-05-05
  • 打赏
  • 举报
回复
protected void BindGridView()
{
this.gvmsg.DataBind();
} 好像没有接定数据愿。
dongjiajia501 2012-05-05
  • 打赏
  • 举报
回复
有数据的
zyydj_10 2012-05-04
  • 打赏
  • 举报
回复
你数据库中有数据么?没有的话可能是空白的

62,268

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧