C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




problems in binding data to a repeater


Posted Date: 11 Jul 2007      Total Responses: 1

Posted By: srinivas.seela       Member Level: Bronze     Points: 2


sir
i am using one repeater .in that one item template.to that item template i binding data through itemdatabound.
while binding data in itemdatabound i want to execute one if -else condition.
if it is 0th record i want to execute IF condition.other wise ELSE part.but i am not able to get record no in itemdatabound.
i am sending my aspx page and aspx.cs also
plz help me.

//my aspx page
<table cellSpacing="0" cellPadding="0" width="219" border="0">
<asp:repeater id="news_rep" Runat="server">
<ItemTemplate>
<tr>
<td><asp:label id="news1_head" Runat="server"></asp:label></td>
</tr>
<tr>
<td id="news_desc" runat="server"></td>
</tr>
<tr>
<td>
<asp:Label ID="news_heading" Runat="server"></asp:Label>
</td>
</tr>
</ItemTemplate>
</asp:repeater>
</table>


// my aspx.cs page

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Configuration;
using AppBlock;
using FormatFunctions;

protected System.Web.UI.WebControls.Repeater news_rep;
protected System.Web.UI.WebControls.Label news1_head;
protected System.Web.UI.WebControls.Label news_heading;
protected System.Web.UI.HtmlControls.HtmlTableCell news_desc;
Dataset ds;
public int i;
public string SqlCon,news1_Heading,news_desctxt,news_headingtxt,sql;



//
SqlCon=ConfigurationSettings.AppSettings["Article"].ToString();
Fillrepeater();


public void Fillrepeater()
{
try
{
sql="SELECT TOP 4 * FROM CMCabnas where section_name='Hot Pursuit' ORDER BY sno desc";
ds=SqlHelper.ExecuteDataset(SqlCon,CommandType.Text,sql);
}
catch(Exception ex)
{
return;
}
string i=ds.Tables[0].rows.count.Tostring();
int j=convert.ToInt32(i);

if(ds.Tables[0].Rows[i].Count >0 )
{
news_rep.DataSource=ds;
news_rep.DataBind();
}



}

private void news_rep_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
if(j=0)
{
news1_head = (Label)e.Item.FindControl("news1_head");
news1_Heading = DataBinder.Eval(e.Item.DataItem,"Heading").ToString();
news_desc=(HtmlTableCell)e.Item.FindControl("news_desc");
news_desctxt=DataBinder.Eval(e.Item.DataItem,"Caption").ToString();

if(news1_Heading.Length <= 38)
{
news1_head.Text = news1_Heading;
}
else
{
news1_head.Text = news1_Heading.Substring(0,38);
}

if(news_desctxt.Length <= 99)
{
news_desc.InnerHtml = news_desctxt+"..";
}
else
{
news_desc.InnerHtml = news_desctxt.Substring(0,99)+"..";
}

}
else

{
news_heading = (Label)e.Item.FindControl("news1_head");
news_headingtxt = DataBinder.Eval(e.Item.DataItem,"Heading").ToString();

if(news_headingtxt.Length <= 38)
{
news_heading.Text = news_headingtxt ;
}
else
{
news_heading.Text = news_headingtxt.Substring(0,38);
}


}


}
}






Responses

Author: Ranjith    11 Jul 2007Member Level: SilverRating:     Points: 2
><asp:label id="news1_head" Runat="server">'<%# DataBinder.Eval(Container.DataItem, " section_name")%>' </asp:label></td>



u try this code



Post Reply
You must Sign In to post a response.
Next : how to give the space in c#
Previous : uploadin the .net application.
Return to Discussion Forum
Post New Message
Category: .NET

Related Messages



dotNet Slackers   BizTalk Adaptors    Web Design

internet fax

Contact Us    Privacy Policy    Terms Of Use