- GridView控件的运用:
-
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False"
CellSpacing="1" Height="1px" PageSize="26" Width="500px" CssClass="txt"
OnPageIndexChanging="GridView1_PageIndexChanging"
OnRowDeleting="GridView1_RowDeleting" OnRowDataBound="GridView1_RowDataBound"
onselectedindexchanged="GridView1_SelectedIndexChanged">
<Columns>
<asp:BoundField DataField="ID" HeaderText="ID" />
<asp:BoundField DataField="title" HeaderText="新闻标题" />
<asp:BoundField DataField="Type" HeaderText="新闻类别" />
<asp:BoundField DataField="IssueDate" HeaderText="发布日期" />
<asp:HyperLinkField HeaderText="编辑" Text="编辑" DataNavigateUrlFields="id"DataNavigateUrlFormatString="Edit.aspx?id={0}" Target="main" />
<asp:CommandField ShowDeleteButton="True" />
</Columns>
</asp:GridView> - DataNavigateUrlFields="id" 是用于提交的字段。
- //如果要提交两个字段,则代码如下:
- //DataNavigateUrlFields="id,name"
//DataNavigateUrlFormatString ="Edit.aspx??id={0}&name={1}" 。 - 这样在RE_HperLink.aspx文件中 sql= "select * from sudents wherr id='"+request.querystring("id")+"'" 就能运行成功了。
- “Edit.aspx?id="{0}"〉这是url传参的方法,把变量id的值传到下一个页面中,变量的名称可以随便起,只要你知道用了哪个名字就可以,因为,你在Edit.aspx里id通过 string questionID = Request.QueryString["id"];来获取它.
- 当有多个页面时,点击下标页面变化的代码:
-
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
GridView1.DataBind();
}