Posts tagged repeater

modify Visible function in repeater of gridview control

Problem:
display label with the text full if the current field equal to zero in repeater or gridview

Solution:
<asp:Label ID=”Label1″ runat=”server” Text=”Full” ForeColor=”Red” Visible=’<%# Convert.ToBoolean(Eval(“name of your field”).ToString().Equals(“0″)? “true”:”false”) %>’>

Repeater inside repeater asp net

Problem :

Putting repeater inside repeater and take ID of parent repeater to bind the  datasourse.

Solution:
hereby the example of code:

in .aspx
<asp:Repeater ID="Repeater2" runat="server"
    onitemdatabound="Repeater2_ItemDataBound">
    <ItemTemplate>
                <asp:Label ID="Label2" runat="server" Text='<%# Eval("Tag") %>'></asp:Label></asp:HyperLink>
        <asp:Repeater ID="Repeater1" runat="server">
        <ItemTemplate>
            (<asp:Label ID="CountID" runat="server" Text='<%# Eval("Expr1") %>'></asp:Label>)
            </ItemTemplate>
        </asp:Repeater>
        <br />
    </ItemTemplate>
</asp:Repeater>

in .aspx cs

private DataTable getDataTableforRepeater2(int TagID)
    {
        SqlConnection conn = new SqlConnection();
        conn.ConnectionString = ConfigurationManager.ConnectionStrings["yourconnectionName"].ConnectionString;

        SqlCommand command = new SqlCommand();
        command.Connection = conn;
        command.CommandText = "sql command";
        DataTable t = new DataTable();
        SqlDataAdapter adapter = new SqlDataAdapter();

        adapter.SelectCommand = command;
        adapter.Fill(t);

        return t;
    }
    protected void Repeater2_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            Repeater Repeater1 = e.Item.FindControl("Repeater1") as Repeater;

            int TagID = int.Parse(DataBinder.Eval(e.Item.DataItem, "TagID").ToString());

            if (TagID != null)
            {
                DataTable t = getDataTableforRepeater2(TagID);
                if (t.Rows.Count > 0)
                {
                    Repeater1.DataSource = t;
                    Repeater1.DataBind();
                }
            }

        }

find value in repeater asp net

Problem:
find value in repeater

Solution:
write this code in itemdatabound on your repeater:

protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            Label title = e.Item.FindControl("Label1") as Label; // depend on what component you r searching for


          Response.Write(title.Text);   // just check          
        }
    }

Get Adobe Flash playerPlugin by wpburn.com wordpress themes