Dawood Abbas

Dawood Abbas

  • NA
  • 264
  • 98.4k

c# paging gridview on selectedvalue of dropdownlist

Mar 12 2015 10:14 AM
public void gridPaymentBind()
{
try
{
//open the db connection if it is closed...
if (connection.State == ConnectionState.Closed)
connection.Open();
command = new SqlCommand();
command.CommandText = "sp_Get_Payment";
command.CommandType = CommandType.StoredProcedure;
command.Connection = connection;
SqlDataAdapter da = new SqlDataAdapter(command);
DataSet ds = new DataSet();
da.Fill(ds);
if (ds.Tables[0].Rows.Count == 0)
{
ds.Tables[0].Rows.Add(ds.Tables[0].NewRow());
gridPaySearch.DataSource = ds;
gridPaySearch.DataBind();
int columncount = gridPaySearch.Rows[0].Cells.Count;
gridPaySearch.Rows[0].Cells.Clear();
gridPaySearch.Rows[0].Cells.Add(new TableCell());
gridPaySearch.Rows[0].Cells[0].ColumnSpan = columncount;
gridPaySearch.Rows[0].Cells[0].Text = "No Records Found";
}
else
{
gridPaySearch.DataSource = ds.Tables[0];
gridPaySearch.DataBind();
lblMessagePaySerach.Visible = false;
}
connection.Close();
}
catch (Exception ex)
{
lblMessagePaySerach.Text = ex.Message;
lblMessagePaySerach.Visible = true;
}
finally //Close db Connection if it is open....
{
if (connection.State == ConnectionState.Open)
connection.Close();
}
}
 
<asp:DropDownList ID="ddlRecordPayment" runat="server" AutoPostBack="True"
onselectedindexchanged="ddlRecordPayment_SelectedIndexChanged">
<asp:ListItem>5</asp:ListItem>
<asp:ListItem>10</asp:ListItem>
<asp:ListItem>25</asp:ListItem>
<asp:ListItem>50</asp:ListItem>
<asp:ListItem>100</asp:ListItem>
</asp:DropDownList>
 
 
 
 How to paging gridview on selectedvalue of dropdownlist in easy way?

Answers (3)