grid view hidden after click on page number index on grid view?

huangapple go评论58阅读模式
英文:

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 &gt; 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 = &quot;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 &#39;Waiting for PDF&#39; when Status=1 then &#39;Waiting for Printing&#39; when Status=2 then &#39;Printed&#39; when Status in (8,9) then &#39;Error in PDF generation&#39; Else &#39;Error in Printing&#39; end as   Status, id from Print_Report  where BranchID=@BranchCode&quot;;
                cmd.CommandType = CommandType.Text;
                cmd.CommandTimeout = 50000;
                cmd.Parameters.AddWithValue(&quot;@BranchCode&quot;, 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

  &lt;asp:GridView ID=&quot;GridViewSearchData&quot; runat=&quot;server&quot; AutoGenerateColumns=&quot;false&quot; DataKeyNames=&quot;ID&quot; CssClass=&quot;table&quot; HeaderStyle-BackColor=&quot;#172b4d&quot;   AllowPaging=&quot;true&quot; OnPageIndexChanging=&quot;grdData_PageIndexChanging&quot; PageSize=&quot;10&quot;&gt;
    &lt;Columns&gt;
        &lt;asp:BoundField DataField=&quot;BranchCode&quot; HeaderText=&quot;BranchCode&quot; HeaderStyle-ForeColor=&quot;White&quot;  /&gt;
    &lt;asp:BoundField DataField=&quot;Status&quot; HeaderText=&quot;Status&quot; HeaderStyle-ForeColor=&quot;White&quot;  /&gt;
    &lt;asp:BoundField DataField=&quot;OrderNo&quot; HeaderText=&quot;OrderNo&quot; ItemStyle-Width=&quot;120px&quot; HeaderStyle-ForeColor=&quot;White&quot;  /&gt;
    &lt;asp:BoundField DataField=&quot;OrderType&quot; HeaderText=&quot;OrderType&quot; HeaderStyle-ForeColor=&quot;White&quot;  /&gt;
    &lt;asp:BoundField DataField=&quot;Printer_name&quot; HeaderText=&quot;Printer_name&quot; HeaderStyle-ForeColor=&quot;White&quot;  /&gt;
    &lt;asp:BoundField DataField=&quot;EntredDatetime&quot; HeaderText=&quot;EntredDatetime&quot; HeaderStyle-ForeColor=&quot;White&quot;  /&gt;                            
    &lt;asp:BoundField DataField=&quot;Id&quot; HeaderText=&quot;Id&quot; ItemStyle-CssClass=&quot;hidden&quot;  HeaderStyle-CssClass=&quot;hidden&quot;  /&gt;
     
    &lt;/Columns&gt;
&lt;/asp:GridView&gt;

答案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(&quot;class&quot;);

after solve issue it like that :

    GridViewSearchData.DataSource = dt;
    GridViewSearchData.DataBind();

huangapple
  • 本文由 发表于 2023年3月3日 21:12:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/75627521.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定