英文:
grid view hidden after click on page number index on grid view?
问题
I work on sp.net web form I face issue grid view Hidden after click on page number on grid view .
所以当点击搜索按钮时,数据显示成功并带有分页。
问题发生在尝试导航或点击网格视图控件上的任何页面时。
点击任何页码时,网格视图隐藏并不显示。
为什么会发生这种情况,如何解决这个问题。
protected void grdData_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridViewSearchData.DataSource = GetDataForSearch(dropBranches.SelectedItem.Value);
GridViewSearchData.PageIndex = e.NewPageIndex;
GridViewSearchData.DataBind();
}
public void BindGrdiview()
{
DataTable dt=new DataTable();
dt = GetDataForSearch(dropBranches.SelectedItem.Value);
if (dt.Rows.Count > 0)
{
GridViewSearchData.DataSource = dt;
GridViewSearchData.DataBind();
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindGrdiview();
}
}
protected void grdData_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridViewSearchData.DataSource = GetDataForSearch(dropBranches.SelectedItem.Value);
GridViewSearchData.PageIndex = e.NewPageIndex;
GridViewSearchData.DataBind();
}
public DataTable GetDataForSearch(string BranchId)
{
string response = string.Empty;
SqlCommand cmd = new SqlCommand();
DataTable dt = new DataTable();
try
{
conn.Open();
cmd.Connection = conn;
cmd.CommandText = "select datelogged AS EntredDatetime, Doc_type AS OrderType,Doc_number as OrderNo, Printer_name, [dbo].[tbl_Branch].vBranchDesc AS BranchCode,case when Status=0 then 'Waiting for PDF' when Status=1 then 'Waiting for Printing' when Status=2 then 'Printed' when Status in (8,9) then 'Error in PDF generation' Else 'Error in Printing' end as Status, id from Print_Report where BranchID=@BranchCode";
cmd.CommandType = CommandType.Text;
cmd.CommandTimeout = 50000;
cmd.Parameters.AddWithValue("@BranchCode", BranchId);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
sda.Fill(dt);
}
catch (Exception ex)
{
response = ex.Message;
}
finally
{
cmd.Dispose();
conn.Close();
}
return dt;
}
aspx页面中的网格视图控件
<asp:GridView ID="GridViewSearchData" runat="server" AutoGenerateColumns="false" DataKeyNames="ID" CssClass="table" HeaderStyle-BackColor="#172b4d" AllowPaging="true" OnPageIndexChanging="grdData_PageIndexChanging" PageSize="10">
<asp:BoundField DataField="BranchCode" HeaderText="BranchCode" HeaderStyle-ForeColor="White" />
<asp:BoundField DataField="Status" HeaderText="Status" HeaderStyle-ForeColor="White" />
<asp:BoundField DataField="OrderNo" HeaderText="OrderNo" ItemStyle-Width="120px" HeaderStyle-ForeColor="White" />
<asp:BoundField DataField="OrderType" HeaderText="OrderType" HeaderStyle-ForeColor="White" />
<asp:BoundField DataField="Printer_name" HeaderText="Printer_name" HeaderStyle-ForeColor="White" />
<asp:BoundField DataField="EntredDatetime" HeaderText="EntredDatetime" HeaderStyle-ForeColor="White" />
<asp:BoundField DataField="Id" HeaderText="Id" ItemStyle-CssClass="hidden" HeaderStyle-CssClass="hidden" />
</asp:GridView>
英文:
I work on sp.net web form I face issue grid view Hidden after click on page number on grid view .
so when click search button data display success with pagination.
issue happen when try to navigate or click on any page on grid view control .
grid view hidden and not display when click to any page number .
why this happen and how to solve this issue .
protected void grdData_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridViewSearchData.DataSource = GetDataForSearch(dropBranches.SelectedItem.Value);
GridViewSearchData.PageIndex = e.NewPageIndex;
GridViewSearchData.DataBind();
}
public void BindGrdiview()
{
DataTable dt=new DataTable();
dt = GetDataForSearch(dropBranches.SelectedItem.Value);
if (dt.Rows.Count > 0)
{
GridViewSearchData.DataSource = dt;
GridViewSearchData.DataBind();
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindGrdiview();
}
}
protected void grdData_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridViewSearchData.DataSource = GetDataForSearch(dropBranches.SelectedItem.Value);
GridViewSearchData.PageIndex = e.NewPageIndex;
GridViewSearchData.DataBind();
}
public DataTable GetDataForSearch(string BranchId)
{
string response = string.Empty;
SqlCommand cmd = new SqlCommand();
DataTable dt = new DataTable();
try
{
conn.Open();
cmd.Connection = conn;
cmd.CommandText = "select datelogged AS EntredDatetime, Doc_type AS OrderType,Doc_number as OrderNo, Printer_name, [dbo].[tbl_Branch].vBranchDesc AS BranchCode,case when Status=0 then 'Waiting for PDF' when Status=1 then 'Waiting for Printing' when Status=2 then 'Printed' when Status in (8,9) then 'Error in PDF generation' Else 'Error in Printing' end as Status, id from Print_Report where BranchID=@BranchCode";
cmd.CommandType = CommandType.Text;
cmd.CommandTimeout = 50000;
cmd.Parameters.AddWithValue("@BranchCode", BranchId);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
sda.Fill(dt);
}
catch (Exception ex)
{
response = ex.Message;
}
finally
{
cmd.Dispose();
conn.Close();
}
return dt;
}
aspx page grid view control
<asp:GridView ID="GridViewSearchData" runat="server" AutoGenerateColumns="false" DataKeyNames="ID" CssClass="table" HeaderStyle-BackColor="#172b4d" AllowPaging="true" OnPageIndexChanging="grdData_PageIndexChanging" PageSize="10">
<Columns>
<asp:BoundField DataField="BranchCode" HeaderText="BranchCode" HeaderStyle-ForeColor="White" />
<asp:BoundField DataField="Status" HeaderText="Status" HeaderStyle-ForeColor="White" />
<asp:BoundField DataField="OrderNo" HeaderText="OrderNo" ItemStyle-Width="120px" HeaderStyle-ForeColor="White" />
<asp:BoundField DataField="OrderType" HeaderText="OrderType" HeaderStyle-ForeColor="White" />
<asp:BoundField DataField="Printer_name" HeaderText="Printer_name" HeaderStyle-ForeColor="White" />
<asp:BoundField DataField="EntredDatetime" HeaderText="EntredDatetime" HeaderStyle-ForeColor="White" />
<asp:BoundField DataField="Id" HeaderText="Id" ItemStyle-CssClass="hidden" HeaderStyle-CssClass="hidden" />
</Columns>
</asp:GridView>
答案1
得分: 0
我解决了问题,我发现了包含网格视图的 CSS 隐藏 div,所以我将其移除了,现在它可以正常工作。
在问题解决之前,代码如下:
GridViewSearchData.DataSource = dt;
GridViewSearchData.DataBind();
PSline.Attributes.Add("class");
问题解决后,代码如下:
GridViewSearchData.DataSource = dt;
GridViewSearchData.DataBind();
英文:
I solved issue , I found class CSS hidden div contain grid view so I remove it And it working .
before issues done it like that :
GridViewSearchData.DataSource = dt;
GridViewSearchData.DataBind();
PSline.Attributes.Add("class");
after solve issue it like that :
GridViewSearchData.DataSource = dt;
GridViewSearchData.DataBind();
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论