| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 760 人关注过本帖
标题:[求助]又是关于gridview的。请各位不吝赐教
取消只看楼主 加入收藏
ice_beiyu
Rank: 1
等 级:新手上路
帖 子:59
专家分:0
注 册:2007-7-10
收藏
 问题点数:0 回复次数:1 
[求助]又是关于gridview的。请各位不吝赐教

小弟有两个页面,两个页面上分别有两个gridview,top.aspx和right.asp。在top.aspx上的gridview中有一个HyperLinkField HeaderText="姓名" Text="姓名"点击这个链接到right.aspx。
现在有两个问题:
1、我要把top.aspx上的gridview中第二列:统筹编号列隐藏,可是在top.aspx.cs中用这个语句
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{

if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[1].Visible = false; //status

}
}
隐藏的效果如下图,数据是隐藏了,可是headtext:统筹编号还在,下面的数据都向左移了一格,对不齐了。

图片附件: 游客没有浏览图片的权限,请 登录注册


2、在right.aspx中我要引用所点击行的统筹编号来从数据库中查寻以便在right.aspx上的grideview上显示详细信息。要如何取得这个统筹编号。
不知道我表达清楚了没有。请各位高手给与指点,谢谢,下面是部分代码:

top.aspx
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4" Font-Size="12px" ForeColor="#333333" GridLines="None" AllowPaging="True" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" OnRowDataBound="GridView1_RowDataBound" OnRowCommand="GridView1_RowCommand">
<FooterStyle BackColor="#507CD1" ForeColor="White" Font-Bold="True" />
<Columns>

<asp:HyperLinkField HeaderText="姓名" Text="姓名" DataNavigateUrlFields="D13" DataNavigateUrlFormatString="right.aspx?Tcbh={0}" Target="mainframe" NavigateUrl="~/right.aspx" DataTextField="D13" >
</asp:HyperLinkField>
<asp:BoundField DataField="Tcbh" HeaderText="统筹编号" SortExpression="Tcbh" />
<asp:BoundField DataField="D16" HeaderText="性别" SortExpression="D16" />
<asp:BoundField DataField="D14a" HeaderText="部门" SortExpression="D14a" />
<asp:BoundField DataField="Gd1" HeaderText="专业" SortExpression="Gd1" />
<asp:BoundField DataField="D30" HeaderText="学历" SortExpression="D30" />
<asp:BoundField DataField="D20" HeaderText="工作时间"SortExpression="D20" />
<asp:BoundField DataField="pyzzr" HeaderText="培养主人"SortExpression="pyzzr" />
<asp:BoundField DataField="pyds" HeaderText="培养直接责任人" SortExpression="pyds" />
<asp:BoundField DataField="zongtimb" HeaderText="总体培养标"SortExpression="zongtimb" />
<asp:BoundField DataField="pynd" HeaderText="年度" SortExpression="pynd" />
<asp:BoundField DataField="ndmb" HeaderText="年度培养目标" SortExpression="ndmb" />
<asp:BoundField DataField="ndjg" HeaderText="年度考核" SortExpression="ndjg" />
<asp:BoundField DataField="pyyd" HeaderText="月度" SortExpression="pyyd" />
<asp:BoundField DataField="ydjh" HeaderText="月度培养计划" SortExpression="ydjh" />
<asp:BoundField DataField="ydjg" HeaderText="月度考核" SortExpression="ydjg" />
<asp:BoundField DataField="ydxuexijl" HeaderText="学习记录" SortExpression="ydxuexijl" />
<asp:BoundField DataField="grxxbg" HeaderText="月度学习报告" SortExpression="grxxbg" />

</Columns>
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#2461BF" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>

top.aspx.cs

public partial class top : System.Web.UI.Page
{
private DBAccess db = null;
private String sql = null,userid=null;
private SqlConnection con = null;
com.sepco3.db.DBConnection dbConnection = null;


protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
bind();
}
}
public void bind()
{
dbConnection = new DBConnection();
sql = "select * from xianshi";
SqlDataAdapter myda = new SqlDataAdapter(sql, dbConnection.getConnection);
DataSet myds = new DataSet();

myda.Fill(myds, "xianshi");
GridView1.DataSource = myds;
GridView1.DataKeyNames = new string[] {"Tcbh" };//主键
GridView1.DataBind();

}

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{

if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[1].Visible = false; //status

}
}
}

right.aspx.cs
public partial class right : System.Web.UI.Page
{


private DBAccess db = null;
private String sql = null,userid=null;
private SqlConnection con = null;
com.sepco3.db.DBConnection dbConnection = null;

protected void Page_Load(object sender, EventArgs e)
{

if (!IsPostBack)
{
bind();
}
}
public void bind()
{
dbConnection = new DBConnection();
sql = "select * from newygxx where Tcbh=从top.aspx中取得的统筹编号;
SqlDataAdapter myda = new SqlDataAdapter(sql, dbConnection.getConnection);
DataSet myds = new DataSet();
myda.Fill(myds, "newygxx");
GridView1.DataSource = myds;
GridView1.DataKeyNames = new string[] { "Tcbh" };//主键
GridView1.DataBind();
}
}


求各位帮帮忙啊,实在是搞不定了。

搜索更多相关主题的帖子: gridview 不吝 
2007-07-25 08:43
ice_beiyu
Rank: 1
等 级:新手上路
帖 子:59
专家分:0
注 册:2007-7-10
收藏
得分:0 

谢谢,非常感谢!问题已经解决!

2007-07-25 09:30
快速回复:[求助]又是关于gridview的。请各位不吝赐教
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018508 second(s), 11 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved