• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 530
  • Last Modified:

dropdownlist value change after post back

it work great when  dropdown selected index change
but when user click on asp:Literal
it value change automatic to 15

using System;
using System.Data;
using System.Data.OleDb;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Text;
 
 
public partial class Solitaire_Ring : System.Web.UI.Page
{
    string connStr = ";
    int _startIndex = 0;
 
    int _thisPage = 1;
 
    int _pageSize;
 
    int _totalNumberOfRows = 0;
    long N_Ip;
    protected void Page_Load(object sender, EventArgs e)
    {
 
        if (Page.IsPostBack)
        {
 
            _pageSize = Convert.ToInt16(Dropperpage.SelectedItem.Text);
      
        }
        if (!IsPostBack)
        {
            _pageSize = Convert.ToInt16(Dropperpage.SelectedItem.Text);
      
            // check for current index
 
            if (Request["start"] != null && Request["page"] != null)
            {
 
                int.TryParse(Request["start"].ToString(), out _startIndex);
 
                int.TryParse(Request["page"].ToString(), out _thisPage);
 
            }
 
            BindGridViewArticels(); // bind articles
 
        }
 
 
        string Ip = "123.236.234.198";
 
        string[] Ip_List = Ip.Split(".".ToCharArray());
 
        string X_Ip = "";
 
 
 
        foreach (string ip in Ip_List)
        {
 
            if (Convert.ToInt16(ip) < 16)
 
                X_Ip += "0" + Convert.ToInt16(ip).ToString("x");
 
            else
 
                X_Ip += Convert.ToInt16(ip).ToString("x");
 
        }
 
 
 
         N_Ip = long.Parse(X_Ip, System.Globalization.NumberStyles.HexNumber);
 
         Getcountry();
 
         
    }
    static uint IPStringToUint(string IPAddressString)
    {
        byte[] addrBytes = System.Net.IPAddress.Parse(IPAddressString).GetAddressBytes();
 
        return ((uint)addrBytes[3] << 24) | ((uint)addrBytes[2] << 16) | ((uint)addrBytes[1] << 8) | (uint)addrBytes[0];
    }
   
    void Getcountry()
    {
 
        SqlConnection cnsql;
        SqlCommand cmsql;
        SqlDataReader drsql;
        cnsql = new SqlConnection(connStr);
 
        cnsql.Open();
 
        string sql = "SELECT * FROM [ipofcountry] WHERE (([BeginingIP] <= '" + N_Ip + "') AND ([EndingIP] >= '" + N_Ip + "' ))";
        cmsql = new SqlCommand(sql, cnsql);
        drsql = cmsql.ExecuteReader();
 
        if (drsql.Read()) 
        {
 
 
            string countryname = drsql["countryname"].ToString();
        }
 
        cnsql.Close();
        cnsql.Dispose();
    }
 
    private void BindGridViewArticels()
    {
 
        DataTable dTable = new DataTable();
 
        using (SqlConnection conn = new SqlConnection(connStr))
        {
 
            using (SqlCommand dCmd = new SqlCommand())
            {
 
                SqlParameter[] prms = new SqlParameter[3];
 
                prms[0] = new SqlParameter("@startRowIndex", SqlDbType.Int);
 
                prms[0].Value = _startIndex;
 
                prms[1] = new SqlParameter("@pageSize", SqlDbType.Int);
 
                prms[1].Value = Dropperpage.SelectedItem.Text;
 
                prms[2] = new SqlParameter("@totalCount", SqlDbType.Int);
 
                prms[2].Direction = ParameterDirection.Output;
 
                dCmd.CommandText = "Solitaire Ring";
 
                dCmd.CommandType = CommandType.StoredProcedure;
 
                dCmd.Parameters.AddRange(prms);
 
                dCmd.Connection = conn;
 
                using (SqlDataAdapter dAd = new SqlDataAdapter())
                {
 
                    // assign the select command to the Adapter object
 
                    dAd.SelectCommand = dCmd;
 
                    // now open the connection
 
                    conn.Open();
 
                    dAd.Fill(dTable);
 
                    conn.Close(); // close the connection
 
                }
 
                _totalNumberOfRows = int.Parse(prms[2].Value.ToString());
 
            }
 
        }
 
        dataring.DataSource = dTable;
 
        dataring.DataBind();
 
 
 
        litPaging.Text = GetPagingDone(_thisPage, _totalNumberOfRows, _pageSize,
 
        "/SDFG/Solitaire Ring.aspx", "");
 
 
 
    }
 
    private string GetPagingDone(int thisPageNo, int totalCount, int pageSize, string pageName, string extraQstringToAdd)
    {
 
        int pageno = 0;
 
        int start = 0;
 
        int loop = totalCount / pageSize;
 
        int remainder = totalCount % pageSize;
 
        StringBuilder strB = new StringBuilder("<br /><b><font color=\"green\">Page:</font> ", 500);
 
        for (int i = 0; i < loop; i++)
        {
 
            pageno = i + 1;
 
            if (pageno.Equals(thisPageNo))
 
                strB.Append(pageno + "&nbsp;| ");
 
            else
 
                strB.Append("<a href=\"" + pageName + "?start=" + start + "&page=" + pageno + extraQstringToAdd + "\" title=\"Go to Page " + pageno + "\">" + pageno + "</a> | ");
 
            start += pageSize;
 
        }
 
        if (remainder > 0)
        {
 
            pageno++;
 
            if (pageno.Equals(thisPageNo))
 
                strB.Append("<b>" + pageno + "&nbsp;</b>| ");
 
            else
 
                strB.Append("<a href=\"" + pageName + "?start=" + start + "&page=" + pageno + extraQstringToAdd + "\" title=\"Go to Page " + pageno + "\">" + pageno + "</a> | ");
 
        }
 
        return strB.ToString() + "</b></span>";
 
    }
    protected void Dropperpage_SelectedIndexChanged(object sender, EventArgs e)
    {
        _pageSize = Convert.ToInt16( Dropperpage.SelectedItem.Text);
        BindGridViewArticels(); 
        
    }
}

Open in new window

0
chandresh43
Asked:
chandresh43
  • 6
  • 4
  • 4
  • +2
2 Solutions
 
waltersnowslinarnoldCommented:
Remove the following code, you 'll reach the solution.

if (Page.IsPostBack)
        {
 
            _pageSize = Convert.ToInt16(Dropperpage.SelectedItem.Text);
     
        }
0
 
muhammadyasirCommented:
use this
use this code on you post back event:
ViewState['dropdowndata']=Dropperpage.SelectedItem.Text;
 
 
use this in page load
if(ViewState['dropdowndata']!=null)
_pageSize = Convert.ToInt16(ViewState['dropdowndata']);

Open in new window

0
 
chandresh43Author Commented:
same problem
not work
look at code
 i change it as you say

using System;
using System.Data;
using System.Data.OleDb;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Text;
 
 
public partial class Solitaire_Ring : System.Web.UI.Page
{
    string connStr = "Data Source=74.86.34.98;Initial Catalog=shivdiamonds;Persist Security Info=True;User ID=shiv;Password=givememore";
    int _startIndex = 0;
 
    int _thisPage = 1;
 
    int _pageSize;
 
    int _totalNumberOfRows = 0;
    long N_Ip;
    protected void Page_Load(object sender, EventArgs e)
    {
 
       if(ViewState["dropdowndata"]!=null)
_pageSize = Convert.ToInt16(ViewState["dropdowndata"]);
 
        if (!IsPostBack)
        {
 
            _pageSize =  Convert.ToInt16(ViewState["dropdowndata"] = DropITEMSPERPAG.SelectedItem.Text);
 
            // check for current index
 
            if (Request["start"] != null && Request["page"] != null)
            {
 
                int.TryParse(Request["start"].ToString(), out _startIndex);
 
                int.TryParse(Request["page"].ToString(), out _thisPage);
 
            }
 
            BindGridViewArticels(); // bind articles
 
        }
 
 
        string Ip = "123.236.234.198";
 
        string[] Ip_List = Ip.Split(".".ToCharArray());
 
        string X_Ip = "";
 
 
 
        foreach (string ip in Ip_List)
        {
 
            if (Convert.ToInt16(ip) < 16)
 
                X_Ip += "0" + Convert.ToInt16(ip).ToString("x");
 
            else
 
                X_Ip += Convert.ToInt16(ip).ToString("x");
 
        }
 
 
 
         N_Ip = long.Parse(X_Ip, System.Globalization.NumberStyles.HexNumber);
 
         Getcountry();
 
         
    }
    static uint IPStringToUint(string IPAddressString)
    {
        byte[] addrBytes = System.Net.IPAddress.Parse(IPAddressString).GetAddressBytes();
 
        return ((uint)addrBytes[3] << 24) | ((uint)addrBytes[2] << 16) | ((uint)addrBytes[1] << 8) | (uint)addrBytes[0];
    }
   
    void Getcountry()
    {
 
        SqlConnection cnsql;
        SqlCommand cmsql;
        SqlDataReader drsql;
        cnsql = new SqlConnection(connStr);
 
        cnsql.Open();
 
        string sql = "SELECT * FROM [ipofcountry] WHERE (([BeginingIP] <= '" + N_Ip + "') AND ([EndingIP] >= '" + N_Ip + "' ))";
        cmsql = new SqlCommand(sql, cnsql);
        drsql = cmsql.ExecuteReader();
 
        if (drsql.Read()) 
        {
 
 
            string countryname = drsql["countryname"].ToString();
        }
 
        cnsql.Close();
        cnsql.Dispose();
    }
 
    private void BindGridViewArticels()
    {
 
        DataTable dTable = new DataTable();
 
        using (SqlConnection conn = new SqlConnection(connStr))
        {
 
            using (SqlCommand dCmd = new SqlCommand())
            {
 
                SqlParameter[] prms = new SqlParameter[3];
 
                prms[0] = new SqlParameter("@startRowIndex", SqlDbType.Int);
 
                prms[0].Value = _startIndex;
 
                prms[1] = new SqlParameter("@pageSize", SqlDbType.Int);
 
                prms[1].Value = Convert.ToInt16(DropITEMSPERPAG.SelectedItem.Text);
                
 
                prms[2] = new SqlParameter("@totalCount", SqlDbType.Int);
 
                prms[2].Direction = ParameterDirection.Output;
 
                dCmd.CommandText = "Solitaire Ring";
 
                dCmd.CommandType = CommandType.StoredProcedure;
 
                dCmd.Parameters.AddRange(prms);
 
                dCmd.Connection = conn;
 
                using (SqlDataAdapter dAd = new SqlDataAdapter())
                {
 
                    // assign the select command to the Adapter object
 
                    dAd.SelectCommand = dCmd;
 
                    // now open the connection
 
                    conn.Open();
 
                    dAd.Fill(dTable);
 
                    conn.Close(); // close the connection
 
                }
 
                _totalNumberOfRows = int.Parse(prms[2].Value.ToString());
 
            }
 
        }
 
        dataring.DataSource = dTable;
 
        dataring.DataBind();
 
 
 
        litPaging.Text = GetPagingDone(_thisPage, _totalNumberOfRows, _pageSize,
 
        "/SDFG/Solitaire Ring.aspx", "");
 
 
 
    }
 
    private string GetPagingDone(int thisPageNo, int totalCount, int pageSize, string pageName, string extraQstringToAdd)
    {
 
        int pageno = 0;
 
        int start = 0;
 
        int loop = totalCount / pageSize;
 
        int remainder = totalCount % pageSize;
 
        StringBuilder strB = new StringBuilder("<br /><b><font color=\"green\">Page:</font> ", 500);
 
        for (int i = 0; i < loop; i++)
        {
 
            pageno = i + 1;
 
            if (pageno.Equals(thisPageNo))
 
                strB.Append(pageno + "&nbsp;| ");
 
            else
 
                strB.Append("<a href=\"" + pageName + "?start=" + start + "&page=" + pageno + extraQstringToAdd + "\" title=\"Go to Page " + pageno + "\">" + pageno + "</a> | ");
 
            start += pageSize;
 
        }
 
        if (remainder > 0)
        {
 
            pageno++;
 
            if (pageno.Equals(thisPageNo))
 
                strB.Append("<b>" + pageno + "&nbsp;</b>| ");
 
            else
 
                strB.Append("<a href=\"" + pageName + "?start=" + start + "&page=" + pageno + extraQstringToAdd + "\" title=\"Go to Page " + pageno + "\">" + pageno + "</a> | ");
 
        }
 
        return strB.ToString() + "</b></span>";
 
    }
 
    protected void DropITEMSPERPAG_SelectedIndexChanged(object sender, EventArgs e)
    {
        _pageSize = Convert.ToInt16(DropITEMSPERPAG.SelectedItem.Text);
      
        BindGridViewArticels();
    }
}

Open in new window

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
waltersnowslinarnoldCommented:
Try the following code.., that will do..
using System;
using System.Data;
using System.Data.OleDb;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Text;
 
 
public partial class Solitaire_Ring : System.Web.UI.Page
{
    string connStr = ";
    int _startIndex = 0;
 
    int _thisPage = 1;
 
    int _pageSize;
 
    int _totalNumberOfRows = 0;
    long N_Ip;
    protected void Page_Load(object sender, EventArgs e)
    {        
        if (!IsPostBack)
        {
            _pageSize = Convert.ToInt16(Dropperpage.SelectedItem.Text);
      
            // check for current index
 
            if (Request["start"] != null && Request["page"] != null)
            {
 
                int.TryParse(Request["start"].ToString(), out _startIndex);
 
                int.TryParse(Request["page"].ToString(), out _thisPage);
 
            }
 
            BindGridViewArticels(); // bind articles
 
        }
 
 
        string Ip = "123.236.234.198";
 
        string[] Ip_List = Ip.Split(".".ToCharArray());
 
        string X_Ip = "";
 
 
 
        foreach (string ip in Ip_List)
        {
 
            if (Convert.ToInt16(ip) < 16)
 
                X_Ip += "0" + Convert.ToInt16(ip).ToString("x");
 
            else
 
                X_Ip += Convert.ToInt16(ip).ToString("x");
 
        }
 
 
 
         N_Ip = long.Parse(X_Ip, System.Globalization.NumberStyles.HexNumber);
 
         Getcountry();
 
         
    }
    static uint IPStringToUint(string IPAddressString)
    {
        byte[] addrBytes = System.Net.IPAddress.Parse(IPAddressString).GetAddressBytes();
 
        return ((uint)addrBytes[3] << 24) | ((uint)addrBytes[2] << 16) | ((uint)addrBytes[1] << 8) | (uint)addrBytes[0];
    }
   
    void Getcountry()
    {
 
        SqlConnection cnsql;
        SqlCommand cmsql;
        SqlDataReader drsql;
        cnsql = new SqlConnection(connStr);
 
        cnsql.Open();
 
        string sql = "SELECT * FROM [ipofcountry] WHERE (([BeginingIP] <= '" + N_Ip + "') AND ([EndingIP] >= '" + N_Ip + "' ))";
        cmsql = new SqlCommand(sql, cnsql);
        drsql = cmsql.ExecuteReader();
 
        if (drsql.Read()) 
        {
 
 
            string countryname = drsql["countryname"].ToString();
        }
 
        cnsql.Close();
        cnsql.Dispose();
    }
 
    private void BindGridViewArticels()
    {
 
        DataTable dTable = new DataTable();
 
        using (SqlConnection conn = new SqlConnection(connStr))
        {
 
            using (SqlCommand dCmd = new SqlCommand())
            {
 
                SqlParameter[] prms = new SqlParameter[3];
 
                prms[0] = new SqlParameter("@startRowIndex", SqlDbType.Int);
 
                prms[0].Value = _startIndex;
 
                prms[1] = new SqlParameter("@pageSize", SqlDbType.Int);
 
                prms[1].Value = Dropperpage.SelectedItem.Text;
 
                prms[2] = new SqlParameter("@totalCount", SqlDbType.Int);
 
                prms[2].Direction = ParameterDirection.Output;
 
                dCmd.CommandText = "Solitaire Ring";
 
                dCmd.CommandType = CommandType.StoredProcedure;
 
                dCmd.Parameters.AddRange(prms);
 
                dCmd.Connection = conn;
 
                using (SqlDataAdapter dAd = new SqlDataAdapter())
                {
 
                    // assign the select command to the Adapter object
 
                    dAd.SelectCommand = dCmd;
 
                    // now open the connection
 
                    conn.Open();
 
                    dAd.Fill(dTable);
 
                    conn.Close(); // close the connection
 
                }
 
                _totalNumberOfRows = int.Parse(prms[2].Value.ToString());
 
            }
 
        }
 
        dataring.DataSource = dTable;
 
        dataring.DataBind();
 
 
 
        litPaging.Text = GetPagingDone(_thisPage, _totalNumberOfRows, _pageSize,
 
        "/SDFG/Solitaire Ring.aspx", "");
 
 
 
    }
 
    private string GetPagingDone(int thisPageNo, int totalCount, int pageSize, string pageName, string extraQstringToAdd)
    {
 
        int pageno = 0;
 
        int start = 0;
 
        int loop = totalCount / pageSize;
 
        int remainder = totalCount % pageSize;
 
        StringBuilder strB = new StringBuilder("<br /><b><font color=\"green\">Page:</font> ", 500);
 
        for (int i = 0; i < loop; i++)
        {
 
            pageno = i + 1;
 
            if (pageno.Equals(thisPageNo))
 
                strB.Append(pageno + "&nbsp;| ");
 
            else
 
                strB.Append("<a href=\"" + pageName + "?start=" + start + "&page=" + pageno + extraQstringToAdd + "\" title=\"Go to Page " + pageno + "\">" + pageno + "</a> | ");
 
            start += pageSize;
 
        }
 
        if (remainder > 0)
        {
 
            pageno++;
 
            if (pageno.Equals(thisPageNo))
 
                strB.Append("<b>" + pageno + "&nbsp;</b>| ");
 
            else
 
                strB.Append("<a href=\"" + pageName + "?start=" + start + "&page=" + pageno + extraQstringToAdd + "\" title=\"Go to Page " + pageno + "\">" + pageno + "</a> | ");
 
        }
 
        return strB.ToString() + "</b></span>";
 
    }
    protected void Dropperpage_SelectedIndexChanged(object sender, EventArgs e)
    {
        _pageSize = Convert.ToInt16( Dropperpage.SelectedItem.Text);
        BindGridViewArticels(); 
        
    }
}

Open in new window

0
 
jeyan10Commented:
hi,

That is because you have a Postback.

If(Page.IsPostBack)
which is not needed.

0
 
chandresh43Author Commented:
i use same code as you post
but not work
when i click on Literal control
it dropdown value change
using System;
using System.Data;
using System.Data.OleDb;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Text;
 
 
public partial class Solitaire_Ring : System.Web.UI.Page
{
    string connStr = "";
 
    int _startIndex = 0;
 
    int _thisPage = 1;
 
    int _pageSize;
 
    int _totalNumberOfRows = 0;
    long N_Ip;
    protected void Page_Load(object sender, EventArgs e)
    {        
         
        if (!IsPostBack)
        {
            _pageSize = Convert.ToInt16(DropITEMSPERPAG.SelectedItem.Text);
      
            // check for current index
 
            if (Request["start"] != null && Request["page"] != null)
            {
 
                int.TryParse(Request["start"].ToString(), out _startIndex);
 
                int.TryParse(Request["page"].ToString(), out _thisPage);
 
            }
 
            BindGridViewArticels(); // bind articles
 
        }
 
 
        string Ip = "123.236.234.198";
 
        string[] Ip_List = Ip.Split(".".ToCharArray());
 
        string X_Ip = "";
 
 
 
        foreach (string ip in Ip_List)
        {
 
            if (Convert.ToInt16(ip) < 16)
 
                X_Ip += "0" + Convert.ToInt16(ip).ToString("x");
 
            else
 
                X_Ip += Convert.ToInt16(ip).ToString("x");
 
        }
 
 
 
         N_Ip = long.Parse(X_Ip, System.Globalization.NumberStyles.HexNumber);
 
         Getcountry();
 
         
    }
    static uint IPStringToUint(string IPAddressString)
    {
        byte[] addrBytes = System.Net.IPAddress.Parse(IPAddressString).GetAddressBytes();
 
        return ((uint)addrBytes[3] << 24) | ((uint)addrBytes[2] << 16) | ((uint)addrBytes[1] << 8) | (uint)addrBytes[0];
    }
   
    void Getcountry()
    {
 
        SqlConnection cnsql;
        SqlCommand cmsql;
        SqlDataReader drsql;
        cnsql = new SqlConnection(connStr);
 
        cnsql.Open();
 
        string sql = "SELECT * FROM [ipofcountry] WHERE (([BeginingIP] <= '" + N_Ip + "') AND ([EndingIP] >= '" + N_Ip + "' ))";
        cmsql = new SqlCommand(sql, cnsql);
        drsql = cmsql.ExecuteReader();
 
        if (drsql.Read()) 
        {
 
 
            string countryname = drsql["countryname"].ToString();
        }
 
        cnsql.Close();
        cnsql.Dispose();
    }
 
    private void BindGridViewArticels()
    {
 
        DataTable dTable = new DataTable();
 
        using (SqlConnection conn = new SqlConnection(connStr))
        {
 
            using (SqlCommand dCmd = new SqlCommand())
            {
 
                SqlParameter[] prms = new SqlParameter[3];
 
                prms[0] = new SqlParameter("@startRowIndex", SqlDbType.Int);
 
                prms[0].Value = _startIndex;
 
                prms[1] = new SqlParameter("@pageSize", SqlDbType.Int);
 
                prms[1].Value = DropITEMSPERPAG.SelectedItem.Text;
 
                prms[2] = new SqlParameter("@totalCount", SqlDbType.Int);
 
                prms[2].Direction = ParameterDirection.Output;
 
                dCmd.CommandText = "Solitaire Ring";
 
                dCmd.CommandType = CommandType.StoredProcedure;
 
                dCmd.Parameters.AddRange(prms);
 
                dCmd.Connection = conn;
 
                using (SqlDataAdapter dAd = new SqlDataAdapter())
                {
 
                    // assign the select command to the Adapter object
 
                    dAd.SelectCommand = dCmd;
 
                    // now open the connection
 
                    conn.Open();
 
                    dAd.Fill(dTable);
 
                    conn.Close(); // close the connection
 
                }
 
                _totalNumberOfRows = int.Parse(prms[2].Value.ToString());
 
            }
 
        }
 
        dataring.DataSource = dTable;
 
        dataring.DataBind();
 
 
 
        litPaging.Text = GetPagingDone(_thisPage, _totalNumberOfRows, _pageSize,
 
        "/SDFG/Solitaire Ring.aspx", "");
 
 
 
    }
 
    private string GetPagingDone(int thisPageNo, int totalCount, int pageSize, string pageName, string extraQstringToAdd)
    {
 
        int pageno = 0;
 
        int start = 0;
 
        int loop = totalCount / pageSize;
 
        int remainder = totalCount % pageSize;
 
        StringBuilder strB = new StringBuilder("<br /><b><font color=\"green\">Page:</font> ", 500);
 
        for (int i = 0; i < loop; i++)
        {
 
            pageno = i + 1;
 
            if (pageno.Equals(thisPageNo))
 
                strB.Append(pageno + "&nbsp;| ");
 
            else
 
                strB.Append("<a href=\"" + pageName + "?start=" + start + "&page=" + pageno + extraQstringToAdd + "\" title=\"Go to Page " + pageno + "\">" + pageno + "</a> | ");
 
            start += pageSize;
 
        }
 
        if (remainder > 0)
        {
 
            pageno++;
 
            if (pageno.Equals(thisPageNo))
 
                strB.Append("<b>" + pageno + "&nbsp;</b>| ");
 
            else
 
                strB.Append("<a href=\"" + pageName + "?start=" + start + "&page=" + pageno + extraQstringToAdd + "\" title=\"Go to Page " + pageno + "\">" + pageno + "</a> | ");
 
        }
 
        return strB.ToString() + "</b></span>";
 
    }
    protected void Dropperpage_SelectedIndexChanged(object sender, EventArgs e)
    {
        
        
    }
    protected void DropITEMSPERPAG_SelectedIndexChanged(object sender, EventArgs e)
    {
        _pageSize = Convert.ToInt16(DropITEMSPERPAG.SelectedItem.Text);
        BindGridViewArticels(); 
    }
}

Open in new window

0
 
codingbeaverCommented:
Where is asp:Literal?
0
 
chandresh43Author Commented:
look at my aspx code
what you think

<table class="FriendsTable">
        <tr>
            <td align="center" colspan="10">
                
                
                  <asp:Panel runat="server" ID="pnlforget" >
   
    <table background="images/detail_shado.jpg" border="0" cellpadding="0" 
        cellspacing="0" style="background-repeat:repeat-x" width="100%">
        <tr>
            <td colspan="3" height="7">
                <asp:Literal ID="litPaging" runat="server" EnableViewState="False" 
                    Mode="PassThrough"></asp:Literal>
            </td>
        </tr>
        <tr>
            <td width="7">
                &nbsp;</td>
            <td>
                <table border="0" cellpadding="2" cellspacing="2" style="width: 98%">
                    <tr>
                        <td class="style13" width="32%" colspan="2">
                            <span class="title">Items per page:</span><a 
                                href="http://shop.ebay.com/i.html?LH_Auction=1&amp;_trkparms=65%253A12%257C66%253A2%257C39%253A1%257C72%253A2464&amp;_nkw=diamond+ring&amp;_ipg=25&amp;_trksid=p3286.c0.m14"></a>&nbsp;<asp:DropDownList 
                                ID="DropITEMSPERPAG" runat="server" AutoPostBack="True" 
                                onselectedindexchanged="DropITEMSPERPAG_SelectedIndexChanged">
                                <asp:ListItem>15</asp:ListItem>
                                <asp:ListItem>30</asp:ListItem>
                            </asp:DropDownList>
                        </td>
                    </tr>
                        
                    <tr>
                        <td class="details3">
                            Submit</td>
                        <td>
                            <asp:Label ID="lblmessage" runat="server" Text="Label"></asp:Label>
                        </td>
                    </tr>
                                        
                </table>
            </td>
            <td width="7">
                &nbsp;</td>
        </tr>
        <tr>
            <td colspan="3" height="7">
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                <asp:HyperLink ID="HyperLink1" runat="server" Text="New User" 
                                    NavigateUrl="~/Register.aspx"   ></asp:HyperLink>
            </td>
        </tr>
    </table>
    </asp:Panel>
                  
                    <asp:DataList ID="dataring" runat="server" RepeatColumns="3" 
                            RepeatDirection="Horizontal" 
                            
                            
                     >
                        <HeaderTemplate>
            <asp:Literal ID="litPagerLinksH" runat="Server"></asp:Literal>
        </HeaderTemplate>
        
        <FooterTemplate>
            <asp:Literal ID="litPagerLinks" runat="Server"></asp:Literal>
        </FooterTemplate>
                        <ItemTemplate>
                            <table bgcolor="#FFFFFF" border="0" cellpadding="0" cellspacing="0" width="230">
                                <tr>
                                    <td height="274" width="230">
                                        <table border="0" cellpadding="0" cellspacing="0" width="230">
                                            <tr>
                                                <td rowspan="2" valign="top" width="9">
                                                    <img alt="" height="80" src="images/box_top_left.jpg" width="8" /></td>
                                                <td height="4">
                                                    <table border="0" cellpadding="0" cellspacing="0" width="100%">
                                                        <tr>
                                                            <td width="100%">
                                                                <img height="3" src="images/box_topl.jpg" width="102" /></td>
                                                            <td width="100%">
                                                                <img height="3" src="images/box_topm.jpg" width="102" /></td>
                                                        </tr>
                                                    </table>
                                                </td>
                                                <td rowspan="2" valign="top" width="9">
                                                    <img alt="" height="80" src="images/box_top_right.jpg" width="9" /></td>
                                            </tr>
                                            <tr>
                                                <td valign="top">
                                                    <table border="0" cellpadding="0" cellspacing="0" width="212">
                                                        <tr>
                                                            <td colspan="3" height="8" valign="top">
                                                                <img alt="" height="8" src="images/box_top1.jpg" width="212" /></td>
                                                        </tr>
                                                        <tr>
                                                            <td background="images/box_left_corner.jpg" height="113" width="9">
                                                                &nbsp;</td>
                                                            <td width="194"  >
                                                                <a class="combobox" href="<%# Eval("prdid", "Ringdetails.aspx?prdid={0}") %>"">
                                                           
                                                                     
                                                                <telerik:radtooltip id="thumbnailTooltip" runat="server" targetcontrolid="Image1"  HideDelay="1000" ManualClose="false" Sticky="true" 
                        relativeto="Element" position="MiddleRight">      
   
                                                                    <asp:Panel ID="Panel2" runat="server">
                                             <asp:Image ID="tooltipImage" ImageUrl='<%# "IMAGES/" + Eval("category")+"/" + Eval("subcategory")+"/"+Eval("image1") %>' runat="server" Width="150px" Height="150px" />   <br />
                                          
                                          
        <table width="98%" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td width="10">&nbsp;</td>
                      <td width="100%">
                          <table border="0" cellpadding="2" cellspacing="2" width="100%">
 
                              <tr>
                                  <td>
                                      Diamond Purity:</td>
                                  <td>
                                      
 
                                      <span id="ctl00_ContentPlaceHolder1_lblringsizeerror" style="color:Red;"><asp:Label runat="server" Text='<%#  Eval("diamondpurity").ToString()  +          Eval("centerdiamondpurity").ToString() %>'> </asp:Label></span>
                                  </td>
                              </tr>
                              <tr>
                                  <td>
                                      Setting </td>
                                  <td>
                                      <span id="ctl00_ContentPlaceHolder1_lblsetting">
                                    <asp:Label runat="server" Text='<%# Eval("diamond_setting") %>'></asp:Label>
                                    </span>
 
                                      </td>
                              
                              </tr>
                              <tr>
                                  <td>
                                      Metal Finish:</td>
                                  <td>
                                      &nbsp;High Polish</td>
                              
                              </tr>
 
                              <tr>
                                  <td>
                                      Fit:</td>
                                  <td>
                                      <span id="ctl00_ContentPlaceHolder1_Label6">Comfort</span>
                                  </td>
                              
                              </tr>
                          </table>
 
                      </td>
                      <td width="10">
                          &nbsp;</td>
                    </tr>
                  <tr>
                    <td colspan="3" class="style12">:</td>
                    </tr>
                </table></td>
 
                
              </tr>
              <tr>
                <td colspan="3"></td>
                </tr>
            </table>
    
                                                                    </asp:Panel>
                                        
                                        
                                        
                                         </telerik:radtooltip>
                                                                
                                                                
                                                                <asp:HyperLink ID="HyperLink2" runat="server" 
                                                                    NavigateUrl= ""   Target="_blank">
                                                                 
                                                          
 <a  href="<%# Eval("prdid", "www.shivdiamonds.com/Ringdetails.aspx?prdid={0}") %>""
   style="cursor: pointer;">
<asp:Image ID="Image1" ImageUrl='<%# "IMAGES/" + Eval("category")+"/" + Eval("subcategory")+"/"+Eval("image1") %>' runat="server" AlternateText='<%# Eval("subcategory") %>' Height="150px" 
                                                                Width="150px" />
     <asp:Label ID="lblimage" runat="server" Text ='<%# Eval("image1") %>'  Visible="false" ></asp:Label>
</a>
  </asp:HyperLink>
                                                                </a>
                                                            </td>
                                                            <td background="images/box_right_corner.jpg" width="9">
                                                                &nbsp;</td>
                                                        </tr>
                                                        <tr>
                                                            <td colspan="3">
                                                                <img alt="" height="6" src="images/box_photo_bo.jpg" width="212" /></td>
                                                        </tr>
                                                    </table>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    &nbsp;</td>
                                                <td background="images/box_center.jpg" height="41">
                                                    <table border="0" cellpadding="0" cellspacing="0" width="100%">
                                                        <tr>
                                                            <td width="9">
                                                                &nbsp;</td>
                                                            <td align="center" class="details">
                                                 
                                                                <asp:Label ID="lblprodname" runat="server" ForeColor="White" 
                                                                    Text='<%# Eval("prodname") %>'></asp:Label>
                                                                <br />
                                                            </td>
                                                            <td width="9">
                                                                &nbsp;</td>
                                                        </tr>
                                                    </table>
                                                </td>
                                                <td>
                                                    &nbsp;</td>
                                            </tr>
                                            <tr>
                                                <td background="images/box_left_sh.jpg" height="80">
                                                    &nbsp;</td>
                                                <td>
                                                    <table border="0" cellpadding="0" cellspacing="0" width="100%">
                                                        <tr>
                                                            <td width="9">
                                                                &nbsp;</td>
                                                            <td class="details2">
                                                                <span class="details3">Details :</span> Diamond Pieces:<asp:Label ID="Label3" 
                                                                    runat="server" Text='<%#  Convert.ToInt32( Eval("diamondpc"))  +   Convert.ToInt32(Eval("centerdiamondpc")) %>' ></asp:Label>
                                                                <br />
                                                                
                                                                Diamond Carat :<asp:Label ID="lbldiamondcarate" runat="server" 
                                                                    Text='<%# Eval("diamondwt") %>'></asp:Label>
                                                                <br />
                                                                <span class="details3">Price :</span>
                                                                <asp:Label ID="Label4" runat="server"></asp:Label>
                                                                <asp:Label ID="PriceLabel" runat="server" Text='<%#  Eval("saleprice") %>'></asp:Label>
                                                                <br />
                                                                <span class="details3">ID : </span>
                                                                <asp:Label ID="lblprdid" runat="server" Text='<%# Eval("prdid") %>'></asp:Label>
                                                            </td>
                                                            <td width="9">
                                                            </td>
                                                            <td width="9">
                                                                &nbsp;</td>
                                                        </tr>
                                                    </table>
                                                </td>
                                                <td background="images/box_left_shr.jpg">
                                                    &nbsp;</td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    <img alt="" height="20" src="images/box_left_bo.jpg" width="9" /></td>
                                                <td background="images/box_bottom.jpg">
                                                    &nbsp;</td>
                                                <td>
                                                    <img alt="" height="20" src="images/box_left_bor.jpg" width="9" /></td>
                                            </tr>
                                        </table>
                                    </td>
                                </tr>
                            </table>
                        </ItemTemplate>
                    </asp:DataList>
    <asp:Panel runat="server" ID="Panel1" >
   
    <table background="images/detail_shado.jpg" border="0" cellpadding="0" 
        cellspacing="0" style="background-repeat:repeat-x" width="100%">
        <tr>
            <td colspan="3" height="7">
                <asp:Literal ID="Literal1" runat="server" EnableViewState="False" 
                    Mode="PassThrough"></asp:Literal>
            </td>
        </tr>
        <tr>
            <td width="7">
                &nbsp;</td>
            <td>
                <table border="0" cellpadding="2" cellspacing="2" style="width: 98%">
                    <tr>
                        <td class="style13" width="32%" colspan="2">
                            <span class="title">Items per page:</span><a 
                                href="http://shop.ebay.com/i.html?LH_Auction=1&amp;_trkparms=65%253A12%257C66%253A2%257C39%253A1%257C72%253A2464&amp;_nkw=diamond+ring&amp;_ipg=25&amp;_trksid=p3286.c0.m14"></a>&nbsp;15,30m</td>
                    </tr>
                        
                    <tr>
                        <td class="details3">
                            Submit</td>
                        <td>
                            <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
                        </td>
                    </tr>
                                        
                </table>
            </td>
            <td width="7">
                &nbsp;</td>
        </tr>
        <tr>
            <td colspan="3" height="7">
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                <asp:HyperLink ID="HyperLink3" runat="server" Text="New User" 
                                    NavigateUrl="~/Register.aspx"   ></asp:HyperLink>
            </td>
        </tr>
    </table>
    </asp:Panel>
                    
            </td>
        </tr>
        
        
    </table>

Open in new window

0
 
waltersnowslinarnoldCommented:
After a postback the dropdown value will be always set to its default. To retain its saved value. you should retrieve from the database and set the selected value. no other solution for this..
0
 
chandresh43Author Commented:
I NOT GET WHAT SAY
PLEASE explain this
with any code
0
 
codingbeaverCommented:
It is not because of the auotposk changing the dropdownlist value. ViewState should keep the dropdownlist selections.

The real cause is that when you click on the paing, you didn't use postback, but submit a new request on the page itself with some query strings (page and start), this will be treated as a new request instead of a PostBack, so all controls on the page will be reset. Take a look at your GetPagingDone function, where you basically use Literal control to generate a hyperlink to the page itself for paging, and this hyperlink will create a brand new request one every click. That is why your dropdownlist is reset every time you click the paging link.

You should use GridView's built-in Paging feature.
0
 
codingbeaverCommented:
I meant to say:
this hyperlink will create a brand new request on every click
0
 
chandresh43Author Commented:
i use session to store value of dropdownlist
and it's work great
 
0
 
waltersnowslinarnoldCommented:
yeah you can do that too. but you should clear the session whenever required, as that value will stay on and disturb your functionality..
0
 
codingbeaverCommented:
Yes, agree. It will work.

I hope you understand the real cause of your problem.
0
 
chandresh43Author Commented:
thanks
all both of  you


0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 6
  • 4
  • 4
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now