Click here to Skip to main content
15,894,646 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have tried the following code but it doesn't display data in the repeater control..
C#
protected void Page_Load(object sender, EventArgs e)
{
  if (!IsPostBack)
  {           
    LOADINGREAPETER();
  }
} 

public void LOADINGREAPETER()
{
  SqlConnection CN = DBUtil.GetCon();
  if (CN.State != ConnectionState.Closed)
    CN.Close();
  CN.Open();        
  string q = "Select Convert(nVarchar,A.Rec_No) CRec,A.Acc_Name Descr,A.Quantity Qty,Convert(nVarchar,A.Sell_Rate) SRate,Sell_CName Sname , Sell_CCode SCCode, Sell_CValue SCValue ,Convert(float,A.Quantity*A.Sell_Rate*Sell_CValue) as SAmount, A.Service_Tax STax,Convert(nVarchar,(A.Quantity*A.Sell_Rate*Sell_CValue)* A.Service_Tax/100)Tax_Amount,Convert(Float,((A.Quantity*A.Sell_Rate*Sell_CValue)+(A.Quantity*A.Sell_Rate*Sell_CValue)* A.Service_Tax/100)) as Net From eLogs_Invoice_Charges_Details A Where A.Invoice_Code='INV1'";
  SqlDataAdapter da = new SqlDataAdapter(q, CN);
  DataTable dtable = new DataTable();
  da.Fill(dtable);
  Repeater1.DataSource = dtable;
  Repeater1.DataBind();
  CN.Close();
}

Please tell me how to bind data.
Posted
Updated 21-Nov-11 0:39am
v2

hi,
plz check this code

<asp:repeater id="Repeater1" runat="server" xmlns:asp="#unknown">
<headertemplate> EmpNo EName  </headertemplate>
<itemtemplate>
<![CDATA[<%#Eval("EmpNo")%>]]>
<![CDATA[<%#Eval("EName")%>]]> 
</itemtemplate>
<footertemplate> *** End Of Records *** </footertemplate>
</asp:repeater>


Code:

protected void Page_Load(object sender, EventArgs e)
{
sqlconnection cn=new sqlconnection("userid=sa;password=123;database=sample");
sqlDataAdapter da=new sqlDataAdapter("Select * from Emp",cn);
dataset ds=new dataset();
da.fill(ds);
Repeater1.DataSource=ds.Tables[0];
Repeater.DataBind();
}
 
Share this answer
 
Hi rajrprk, create your .aspx page with, Itemtemplate.like these u can do.
C#
<ASP:Repeater 
    id="rpt1"
     runat="server"
    >
    <HeaderTemplate>
        <table width="100%" style="font: 8pt verdana">
        <tr style="Background-Color:DFECD8">
        <td>First Name</td>
        <td>Last Name</td>
       
        </tr>
    </HeaderTemplate>
    <itemtemplate>
        <tr style="Background-Color:FFECD9">
        <td>
            <%# DataBinder.Eval(Container.DataItem, "first_name")%>
        </td>
        <td>
            <%# DataBinder.Eval(Container.DataItem, "last_name")%>
        </td>
       
        </tr>
    </itemtemplate>
    <alternatingitemtemplate>
        <tr style="Background-Color:FFECA8">
        <td>
            <%# DataBinder.Eval(Container.DataItem, "first_name")%>
        </td>
        <td>
            <%# DataBinder.Eval(Container.DataItem, "last_name")%>
        </td>
        
        </tr>
    </alternatingitemtemplate>
    <separatortemplate>
        <tr style="Background-Color:White">
        <td> </td>
        <td> </td>
       
        </tr>
    </separatortemplate>
    <footertemplate>
        <tr style="Background-Color:DFECD8">
        <td>First Name</td>
        <td>Last Name</td>
       
        </tr>
        </footertemplate></table>


code behind part is ok.
 
Share this answer
 
v2
What is your markup code? Then only we can help you. Meanwhile you can refer the link

Click here

You need to define the template for every column.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900