谁能说出如何将数据绑定到中继器控件中 [英] Can anyone say how to bind data in to repeater control

查看:37
本文介绍了谁能说出如何将数据绑定到中继器控件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试了以下代码,但在中继器控件中未显示数据.

I have tried the following code but it doesn''t display data in the repeater control..

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.

推荐答案

您的标记代码是什么?只有我们才能为您提供帮助.同时,您可以参考链接

单击此处

您需要为每列定义模板.
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.


您好rajrprk,使用Itemtemplate创建您的.aspx页面,就像您可以做到的那样.
Hi rajrprk, create your .aspx page with, Itemtemplate.like these u can do.
<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.



请检查此代码


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();
}


这篇关于谁能说出如何将数据绑定到中继器控件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆