我有一个Gridview Control
包含标签模板字段。在 RowDataBound 期间填充标签值。当我除了这个模板字段进行分页时,所有的都是分页的。我认为,当进行分页时,每次标签模板字段都填写在RowDataBound
.
现在我做不到pagination
。请帮忙
这是我的代码
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="3" OnDataBound="GridView1_DataBound" OnPageIndexChanging="GridView1_PageIndexChanging1" OnRowDataBound="GridView1_RowDataBound1" PageSize="3">
<Columns>
<asp:TemplateField HeaderText="First Row">
<ItemTemplate>
<asp:Label ID="Label1" runat="server">Text</asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="White" ForeColor="#000066" />
<HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
<RowStyle ForeColor="#000066" />
<SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F1F1F1" />
<SortedAscendingHeaderStyle BackColor="#007DBB" />
<SortedDescendingCellStyle BackColor="#CAC9C9" />
<SortedDescendingHeaderStyle BackColor="#00547E" />
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
GridView.cs
protected void Page_Load(object sender, EventArgs e)
{
Getdata();
}
public void Getdata()
{
SqlConnection con = new SqlConnection("Data Source=CMH-SOSQL\\SQ1;Initial Catalog=RPT2020_DEV;Integrated Security=True");
con.Open();
string qry = "use PID2020_DEV select * from batch_void_rsn_cd";
SqlDataAdapter da = new SqlDataAdapter(qry, con);
DataTable dt = new DataTable();
da.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
GridView1.Columns[0].HeaderText = "First Row";
Label lblKey = (Label)e.Row.FindControl("Label1");
lblKey.Text = e.Row.RowIndex.ToString();
}
}
protected void GridView1_DataBound(object sender, EventArgs e)
{
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
Getdata();
}