0

hi all i am creating web site accidently i am facing one bug like i didn see pagging on grid after doing same thing on another form it works perfect
Please look into my pronlem i am posting my Code here Please Help ASAP
Thanks In advance

This is my Grid Markup

<td colspan="3">
                             <asp:GridView ID="GridView1" AllowPaging="true" runat="server" 
                            OnRowCreated="GridView1_RowCreated" OnSorting="GridView1_Sorting" PageSize="500" OnPageIndexChanging="GridView1_PageIndexChanging"
                            SkinID="IncGrid" AutoGenerateColumns="true" onrowcommand="GridView1_RowCommand1"  Width="100%">
                        </asp:GridView>
                    </td>

and this is all related Events of grid

private void FillGrid()
    {
        DataSet ds = new DataSet();
        string sDowntime = "";
        if (txtDownTime.Text.Length > 0)
        {
            sDowntime = Convert.ToDateTime(txtDownTime.Text).ToString("yyyy-MM-dd");
        }
        oVenIntg.ViewSuccessLogs(out ds, "TataDesk", ddlVendor.SelectedItem.Value, ddlFilter.SelectedValue.ToString(),
            searchTicketNo.Text.Trim(), txtDeviceID.Text.Trim(), sDowntime);


        if (ds.Tables[0].Rows.Count > 0)
        {
            GridView1.DataSource = ds.Tables[0].DefaultView;
            GridView1.DataBind();

            lblMsg.ForeColor = System.Drawing.Color.Green;
            lblMsg.Text = ds.Tables[0].Rows.Count.ToString() + " items found.";
        }
        else
        {
            GridView1.DataSource = null;
            GridView1.DataBind();

            lblMsg.ForeColor = System.Drawing.Color.Red;
            lblMsg.Text = "No Records Found.";
        }

        ds.Dispose();
    }
    protected void GridView1_RowCommand1(object sender, GridViewCommandEventArgs e)
    {

    }
     private void SortGridView(string sortExpression, string direction)
    {
        DataSet ds = new DataSet();
        //oVenIntg.ViewErrorLogs(out ds, "TataDesk", ddlVendor.SelectedItem.Value, ddlFilter.SelectedValue.ToString(), searchTicketNo.Text.Trim(), txtDeviceID.Text.Trim(), txtDownTime.Text.Trim());
        string sDowntime = "";
        if (txtDownTime.Text.Length > 0)
        {
            sDowntime = Convert.ToDateTime(txtDownTime.Text).ToString("yyyy-MM-dd");
        }
        oVenIntg.ViewSuccessLogs(out ds, "TataDesk", ddlVendor.SelectedItem.Value, ddlFilter.SelectedValue.ToString(),
            searchTicketNo.Text.Trim(), txtDeviceID.Text.Trim(), sDowntime);

        //DataTable dt = new DataTable();
        //dt.Merge(ds.Tables[0]);

        //foreach (DataColumn dc in dt.Columns)
        //{
        //    if (dc.ColumnName.StartsWith("i"))
        //    {
        //        ds.Tables[0].Columns.Remove(dc.ColumnName);

        //    }
        //}

        //dt = ds.Tables[0];
        DataView dv = new DataView(ds.Tables[0]);
        dv.Sort = sortExpression + direction;
        GridView1.DataSource = dv;
        GridView1.DataBind();

        ds.Dispose();
        //dt.Dispose();
        dv.Dispose();
    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        if (ViewState["SortExp"] == null)
        {
            FillGrid();
        }
        else
        {
            SortGridView(ViewState["SortExp"].ToString(), ReturnSortOrder(ViewState["sortDirection"].ToString()));
        }
    }

    private void ApplyScroll1(System.Web.UI.WebControls.GridViewRowEventArgs e)
    {
        e.Row.Attributes.Add("onmouseover", "ov(this)");
        e.Row.Attributes.Add("onmouseout", "ou(this," + e.Row.RowIndex + ")");
        e.Row.Attributes.Add("onClick", "oc(this)");
        e.Row.Attributes.Add("id", "r" + e.Row.RowIndex);
    }


    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowIndex != -1)
        {
            ApplyScroll1(e);
        }
    }
    private const string ASCENDING = " ASC";
    private const string DESCENDING = " DESC";
    private SortDirection GridViewSortDirection
    {
        get
        {
            if (ViewState["sortDirection"] == null)
                ViewState["sortDirection"] = SortDirection.Ascending;

            return (SortDirection)ViewState["sortDirection"];
        }
        set { ViewState["sortDirection"] = value; }
    }

    protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
    {
        string sortExpression = e.SortExpression;
        ViewState["SortExp"] = e.SortExpression;
        if (GridViewSortDirection == SortDirection.Ascending)
        {
            GridViewSortDirection = SortDirection.Descending;
            SortGridView(sortExpression, DESCENDING);
        }
        else
        {
            GridViewSortDirection = SortDirection.Ascending;
            SortGridView(sortExpression, ASCENDING);
        }
    }
    private string ReturnSortOrder(string strValue)
    {
        string strSortOrder;
        if (ViewState["sortDirection"].ToString().Contains("Ascending"))
        {
            strSortOrder = " ASC";
        }
        else
        {
            strSortOrder = " DESC";
        }
        return strSortOrder;
    }
    protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
    {
        try
        {
            e.Row.Cells[0].CssClass = "hiddencol";
            e.Row.Cells[12].CssClass = "hiddencol";

        }
        catch { }
    }
1
Contributor
1
Reply
7
Views
4 Years
Discussion Span
Last Post by hirenpatel53
1

Got solution there is problem with my Code

i replaced following code and its work

protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
    {
        try
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Cells[0].CssClass = "hiddencol";
                e.Row.Cells[12].CssClass = "hiddencol";
            }
            else if (e.Row.RowType == DataControlRowType.Header)
            {
                e.Row.Cells[0].CssClass = "hiddencol";
                e.Row.Cells[12].CssClass = "hiddencol";
            }

        }
        catch { }
    }
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.