.aspx page Code:
<div>
<table>
<tr>
<asp:Repeater ID="rp" runat="server" >
<ItemTemplate>
<td style="width:100px;">
<asp:LinkButton ID="lbItem" runat="server" Text='<%#Eval("name") %>'></asp:LinkButton>
<asp:Label ID="lblid" runat="server" Text='<%#Eval("id") %>' Visible="false"></asp:Label>
</td>
</ItemTemplate>
</asp:Repeater>
</tr>
<tr>
<td colspan="4" align="right">
<asp:LinkButton ID="lbtnBackword" runat="server" CommandName="bck" Text="Previous"
CommandArgument="" onclick="lbtnBackword_Click"></asp:LinkButton>
<asp:LinkButton ID="lbtnForward" runat="server" CommandName="fwd" Text="Next"
CommandArgument="" onclick="lbtnForward_Click"></asp:LinkButton>
</td>
</tr>
</table>
</div>
.aspx.cs page code:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
Fill_Repeater(0);
}
void Fill_Repeater(int t)
{
SqlConnection SqlCon = new SqlConnection(@"Data Source=SQLEXPRESS;Initial Catalog=mydb;User ID=sa;Password=sa");
SqlCon.Open();
SqlCommand SqlCmd = new SqlCommand("select top 4 Cust_Id as id ,[First Name] as 'name' from tbl_Customer where cust_id not in (select top (4*" + t + ") cust_id from tbl_Customer)", SqlCon);
SqlDataAdapter da = new SqlDataAdapter(SqlCmd);
DataSet ds = new DataSet();
da.Fill(ds);
rp.DataSource = ds;
rp.DataBind();
lbtnBackword.CommandArgument = (t - 1).ToString();
lbtnForward.CommandArgument = (t + 1).ToString();
if (t == 0)
lbtnBackword.Visible = false;
else
lbtnBackword.Visible = true;
if (ds.Tables[0].Rows.Count < 4)
lbtnForward.Visible = false;
else
lbtnForward.Visible = true;
}
protected void lbtnBackword_Click(object sender, EventArgs e)
{
Fill_Repeater(Convert.ToInt32(lbtnBackword.CommandArgument.ToString()));
}
protected void lbtnForward_Click(object sender, EventArgs e)
{
Fill_Repeater(Convert.ToInt32(lbtnForward.CommandArgument.ToString()));
}
o/p:
Tag: binding Repeater control in asp.net, binding Repeater control with paginagtion in asp.net, Binding repeater in asp.net, Binding repeater in asp.net with pagination, Repeater in asp.net
<div>
<table>
<tr>
<asp:Repeater ID="rp" runat="server" >
<ItemTemplate>
<td style="width:100px;">
<asp:LinkButton ID="lbItem" runat="server" Text='<%#Eval("name") %>'></asp:LinkButton>
<asp:Label ID="lblid" runat="server" Text='<%#Eval("id") %>' Visible="false"></asp:Label>
</td>
</ItemTemplate>
</asp:Repeater>
</tr>
<tr>
<td colspan="4" align="right">
<asp:LinkButton ID="lbtnBackword" runat="server" CommandName="bck" Text="Previous"
CommandArgument="" onclick="lbtnBackword_Click"></asp:LinkButton>
<asp:LinkButton ID="lbtnForward" runat="server" CommandName="fwd" Text="Next"
CommandArgument="" onclick="lbtnForward_Click"></asp:LinkButton>
</td>
</tr>
</table>
</div>
.aspx.cs page code:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
Fill_Repeater(0);
}
void Fill_Repeater(int t)
{
SqlConnection SqlCon = new SqlConnection(@"Data Source=SQLEXPRESS;Initial Catalog=mydb;User ID=sa;Password=sa");
SqlCon.Open();
SqlCommand SqlCmd = new SqlCommand("select top 4 Cust_Id as id ,[First Name] as 'name' from tbl_Customer where cust_id not in (select top (4*" + t + ") cust_id from tbl_Customer)", SqlCon);
SqlDataAdapter da = new SqlDataAdapter(SqlCmd);
DataSet ds = new DataSet();
da.Fill(ds);
rp.DataSource = ds;
rp.DataBind();
lbtnBackword.CommandArgument = (t - 1).ToString();
lbtnForward.CommandArgument = (t + 1).ToString();
if (t == 0)
lbtnBackword.Visible = false;
else
lbtnBackword.Visible = true;
if (ds.Tables[0].Rows.Count < 4)
lbtnForward.Visible = false;
else
lbtnForward.Visible = true;
}
protected void lbtnBackword_Click(object sender, EventArgs e)
{
Fill_Repeater(Convert.ToInt32(lbtnBackword.CommandArgument.ToString()));
}
protected void lbtnForward_Click(object sender, EventArgs e)
{
Fill_Repeater(Convert.ToInt32(lbtnForward.CommandArgument.ToString()));
}
o/p:
Tag: binding Repeater control in asp.net, binding Repeater control with paginagtion in asp.net, Binding repeater in asp.net, Binding repeater in asp.net with pagination, Repeater in asp.net
No comments:
Post a Comment