hi friends
i'm listing magazine upon category select from dropdown
my problem is i'm getting the records from previously selected page
number
that's if i select category from dropdown then click on page number (2
or 3)
when i go and again select category from dropdown records are
displayed from page number to on datagrid.
please help me
here is my code
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList
ID="DropDownList1" runat="server" AutoPostBack="true"
DataSourceID="ObjectDataSource1" DataTextField="Category_Name"
DataValueField="Category_Name"
OnSelectedIndexChanged="DropDownList1_OnSelectedIndexChanged">
</asp:DropDownList><asp:ObjectDataSource
ID="ObjectDataSource1" runat="server" SelectMethod="LoadCategory"
TypeName="CategoryDetails"></asp:ObjectDataSource>
<asp:DataGrid ID="maglist" Runat="server"
BorderColor="Navy" BorderWidth="2px"
AutoGenerateColumns="False"
Width="50%"
HorizontalAlign="Center"
OnPageIndexChanged="maglist_PageIndexChanged"
AllowPaging="True"
PageSize="15"
>
<HeaderStyle HorizontalAlign="Center" CssClass="tableHeader" />
<ItemStyle CssClass="tableCellNormal" />
<AlternatingItemStyle CssClass="tableCellAlternating" />
<Columns>
<asp:BoundColumn HeaderText="Magazine_name"
DataField="Magazine_name" />
<asp:BoundColumn DataField="magazine_description"
HeaderText="magazine_description">
</asp:BoundColumn>
</Columns>
<PagerStyle Mode="NumericPages" />
</asp:DataGrid>
<br />
</div>
</form>
</body>
C#.net
<script runat="server">
private void bindData()
{
SqlConnection myConn = null;
SqlDataAdapter da = null;
DataSet dSet = null;
String strConnection;
String strSQL;
try
{
myConn = new SqlConnection
(ConfigurationSettings.AppSettings["wrs"]);
myConn.Open();
string searchText =
DropDownList1.SelectedValue.ToString();
if (DropDownList1.Text.Contains("'"))
{
searchText = DropDownList1.Text.Replace("'",
"\''");
}
string query = "Select a.Category_Id,
a.Category_Name,b.umc,b.Magazine_Name,Magazine_Description From
[magazine_category] a Inner Join magazine b on a.Category_Id =
b.Category_Id and a.Category_Name = '" + searchText + "' ORDER BY
b.Magazine_Name ASC";
da = new SqlDataAdapter(query, myConn);
dSet = new DataSet();
da.Fill(dSet);
maglist.DataSource = dSet;
maglist.DataBind();
}
finally
{
if (myConn != null)
{
myConn.Close();
}
}
}
protected void DropDownList1_OnSelectedIndexChanged(object sender,
EventArgs e)
{
maglist.DataBind();
bindData();
}
protected void maglist_PageIndexChanged(object sender,
DataGridPageChangedEventArgs e)
{
maglist.CurrentPageIndex = e.NewPageIndex;
bindData();
}
</script>