Set control inside the
Repeater
<asp:Repeater ID="Repeater1"
runat="server" OnItemCommand="Repeater1_ItemCommand">
<ItemTemplate>
<label>
Title :
<%#
Eval("ptitle")%>
</label>
-------------------------------------------------------------------------------------
<asp:Label ID="Name1"
runat="server" ForeColor="Red" Font-Bold="true"
Text='<%#Eval("name") %>'/>
-------------------------------------------------------------------------------------
<asp:LinkButton
ID="Link_like" runat="server" Text="Like"
CommandName="cmd_like"
CommandArgument='<%# Eval("sno")%>' />
-------------------------------------------------------------------------------------
<asp:Button ID="Button3"
runat="server"
style="color: #FFFFFF; font-weight: 700; background-color: #336699"
CommandArgument='<%# Eval("sno")%> CommandName="cmd_show"
Text="Comment"/>
-------------------------------------------------------------------------------------
<asp:Panel
ID="view1" runat="server">
</panel>
<img
src='/portal/upload/<%#
DataBinder.Eval(Container.DataItem, "pic") %>' alt="" style="height:60px;width:50px;"/>
<asp:LinkButton
ID="btn_comment" runat="server" Text="View
Comment"
CommandName="cmd_comment"
CommandArgument='<%#
Eval("sno")%>'
/>
<asp:LinkButton
ID="Link_like" runat="server" Text="Like" CommandName="cmd_like" CommandArgument='<%#
Eval("sno")%>'
/>
========================================================================================
Display previous
and next record
<input id="txtHidden"
style="width: 28px" type="hidden" value="0"
runat="server" />
<asp:LinkButton ID="lnkBtnPrev"
runat="server" Font-Underline="False"
OnClick="lnkBtnPrev_Click"
Font-Bold="True"><< Prev </asp:LinkButton>
<asp:LinkButton
ID="lnkBtnNext" runat="server"
Font-Underline="False"
OnClick="lnkBtnNext_Click"
Font-Bold="True">Next >></asp:LinkButton>
How to
get control value
from Repeater Control
protected void showcomment()
{
string cs = ConfigurationManager.AppSettings["mydb"];
cn17
= new SqlConnection(cs);
cn17.Open();
for (int i = 0; i
< Repeater1.Items.Count; i++)
{
Label rec = Repeater1.Items[i].FindControl("lblcomment") as
Label;
Label lblike = Repeater1.Items[i].FindControl("lbllike") as
Label;
Label dispcomment =
Repeater1.Items[i].FindControl("disp_comment")
as Label;
Label displike = Repeater1.Items[i].FindControl("disp_like") as
Label;
string k = "select
count(recno) from ideacomment where recno='" + rec.Text + "'";
cm17 = new SqlCommand(k,
cn17);
dispcomment.Text = cm17.ExecuteScalar().ToString();
string k2 = "select
count(recno) from idealike where recno='" + lblike.Text + "'";
cm17 = new SqlCommand(k2,
cn17);
displike.Text = cm17.ExecuteScalar().ToString();
}
}
How to
use Repeater control
event
protected
void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
{
string cs =
ConfigurationManager.AppSettings["mydb"];
if (e.CommandName ==
"cmd_show") // check command is cmd_delete
{
int CustomerID =
Convert.ToInt32(e.CommandArgument);
Label22.Text =
CustomerID.ToString();
cn17 = new SqlConnection(cs);
cn17.Open();
string k1 = "select *
from pidea where sno='" +
Label22.Text + "'";
cm17 = new SqlCommand(k1, cn17);
dr17 = cm17.ExecuteReader();
if (dr17.Read())
{
Label29.Text =
dr17[8].ToString();
}
dr17.Close();
// TextBox myTextBox =
(TextBox)Repeater1.FindControl("TextBox1");
TextBox TextBox1 =
(TextBox)e.Item.FindControl("TextBox1");
string k = "insert into
ideacomment values('" + Label22.Text + "','" + Label24.Text +
"','" + Label25.Text + "','" + Label29.Text +
"','" + Label26.Text + "','" + TextBox1.Text +
"','" + Label27.Text + "','" + Label28.Text +
"')";
cm17 = new SqlCommand(k, cn17);
cm17.ExecuteNonQuery();
Label29.Text = "";
Label22.Text = "";
TextBox1.Text = "";
cn17.Close();
showcomment();
}
if (e.CommandName ==
"cmd_comment") // check command is cmd_delete
{
Panel pan1 =
(Panel)e.Item.FindControl("view1");
Repeater rep1 =
(Repeater)e.Item.FindControl("Repeater2");
// pan1.Visible = true;
int CustomerID =
Convert.ToInt32(e.CommandArgument);
Label30.Text =
CustomerID.ToString();
cn17 = new SqlConnection(cs);
cn17.Open();
DataTable dt = new DataTable();
SqlDataAdapter adp = new
SqlDataAdapter("SELECT * FROM ideacomment where recno='" +
Label30.Text + "'", cn17);
adp.Fill(dt);
rep1.DataSource = dt;
rep1.DataBind();
cn17.Close();
}
if (e.CommandName ==
"cmd_like") // send like to
{
int CustomerID =
Convert.ToInt32(e.CommandArgument);
Label31.Text =
CustomerID.ToString();
cn17 = new SqlConnection(cs);
cn17.Open();
string k21 = "insert into
idealike values('" + Label25.Text + "','" + Label26.Text +
"','" + Label31.Text + "')";
cm17 = new SqlCommand(k21, cn17);
cm17.ExecuteNonQuery();
Label31.Text = "";
showcomment();
}
}