小弟有两个页面,两个页面上分别有两个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();
}
}
求各位帮帮忙啊,实在是搞不定了。