当前位置:编程学习 > C#/ASP.NET >>

100分,求一dataList样式,请高手赐教!!

大概是这样:
__________
|        |  公司名称:
|        |  电    话:
|  图片   |  联 系 人:
|        |  地    址:
|________|

......
..........

.....分页

给例子(E-Mail:119598566@qq.com)或贴上源码给兄弟,谢谢!实在在网上找不到解决方法,请高手赐教!!
--------------------编程问答-------------------- 自己先顶,高手赐教 --------------------编程问答-------------------- dataList样式是自己写的,我这时候没有,下次过来给你. --------------------编程问答-------------------- 谢谢 yuanhubin

希望高手现身 --------------------编程问答-------------------- 后台的代码,你看看已经可以的根据你的字段情况改一下字段名:  
protected void Page_Load(object sender, EventArgs e)
    {
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        if (!Page.IsPostBack)
        {
           
            GridReadData(这里面是Request.QueryString传的ID值以此来查询单个记录);
        }
    }
       protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
    {
 
    }
    private DataTable getdt(DataTable dt)
    {

        for (int i = 0; i < dt.Rows.Count; i++)
        {

            dt.Rows[i]["字段"] = dt.Rows[i]["字段"].ToString().Replace("\r\n", "<br>");
            dt.Rows[i]["字段"] = dt.Rows[i]["字段"].ToString().Replace("\r\n", "<br>");
           
        }
        return dt;
    }
    void GridReadData(string id)
    {
        DataTable dt = null;
        DataTable dtmp = null;

        string strError = "";
        if (id == null)
        {
        
            id = "";
        }
      此处作判断显示全部还是带分页的单条显示!
   
        SC_DbAccess.GET_A_NewsMang(ref dt, id, ref strError);

        DataList1.DataSource = getdt(dt);
        DataList1.DataBind();
        SC_DbAccess.GET_A_NewsMang(ref dtmp, "", ref strError);
        for (int i = 0; i < dtmp.Rows.Count; i++)
        {
            if (id == dtmp.Rows[i]["id"].ToString())
            {
                if (i == 0)
                {
                    LinkButton1.Visible = false;
                    LinkButton1.ToolTip = "";
                }
                else
                {
                    LinkButton1.Visible = true;
                    LinkButton1.Text = "上一篇:" + dtmp.Rows[i - 1]["字段"].ToString();
                    LinkButton1.ToolTip = dtmp.Rows[i - 1]["id"].ToString();
                }
                if (i == dtmp.Rows.Count - 1)
                {
                    LinkButton2.Visible = false;
                    LinkButton2.ToolTip = "";
                }
                else
                {
                    LinkButton2.Visible = true;
                    LinkButton2.Text = "下一篇:" + dtmp.Rows[i + 1]["字段"].ToString();
                    LinkButton2.ToolTip = dtmp.Rows[i + 1]["id"].ToString();
                }
                return;
            }
        }

    }
       protected void LinkButton1_Click(object sender, EventArgs e)
    {
        GridReadData(LinkButton1.ToolTip);
    }
    protected void LinkButton2_Click(object sender, EventArgs e)
    {
        GridReadData(LinkButton2.ToolTip);

    }
}
--------------------编程问答-------------------- SC_DbAccess.GET_A_NewsMang(ref   dt,   id,   ref   strError); 
这个是查询数据库的获取查询出的值!
这个是前台的,其中Text='<%# Bind("字段") %>'中的字段为你要显示数据的字段名称!
根据你的需要自已改一下!

    <form id="form1" runat="server">
    <div>
      <asp:DataList id="DataList1" runat="server" OnItemDataBound="DataList1_ItemDataBound"><ItemTemplate>
<TABLE style="WIDTH: 100%" id="Table2">
<TR>
<TD rowSpan=4>
<asp:Label id="Label1" runat="server" Text='<%# Bind("图片地址字段") %>'></asp:Label>
</TD>
<TD style="HEIGHT: 39px">公司名称:</TD>
<TD style="HEIGHT: 39px"><asp:Label id="Label2" runat="server" Text='<%# Bind("字段") %>'></asp:Label>
</TD>
</TR>
<TR>
<TD>电         话:</TD><TD><asp:Label id="Label3" runat="server" Text='<%# Bind("字段") %>'></asp:Label></TD>
</TR>
<TR>
<TD> 联   系   人:</TD>
<TD><asp:Label id="Label4" runat="server" Text='<%# Bind("字段") %>'></asp:Label></TD>
</TR>
<TR>
<TD>  地         址:</TD>
<TD><asp:Label id="Label5" runat="server" Text='<%# Bind("字段") %>'></asp:Label></TD>
</TR>
</TABLE>
</ItemTemplate>
</asp:DataList>
<table style="height: 36px" width="100%">
    <tr>
        <td colspan="2">
            <asp:linkbutton id="LinkButton1" runat="server" onclick="LinkButton1_Click"></asp:linkbutton>
        </td>
        <td style="text-align: right">
            <asp:linkbutton id="LinkButton2" runat="server" onclick="LinkButton2_Click"></asp:linkbutton>
        </td>
    </tr>
    <tr>
        <td colspan="2">
            <asp:button id="Button1" runat="server" onclick="Button1_Click" text="返回" visible="False" />
        </td>
        <td>
        </td>
    </tr>
</table>
         </div>
    </form> --------------------编程问答-------------------- 发完接分了! --------------------编程问答-------------------- datalist 好象没有分页的功能用datalistview可以 --------------------编程问答-------------------- 分数少不了,我试试先 --------------------编程问答-------------------- 都两年多了,怎么还没看到你结帖呢!~~~
--------------------编程问答-------------------- 但愿楼主还健在 --------------------编程问答-------------------- 接分 --------------------编程问答-------------------- mark --------------------编程问答-------------------- 图片设置 align="left"或者style="float:left"就可以了,分页可以用我的AspNetPager分页控件 --------------------编程问答-------------------- 在datalist中用div切割啊,左边图片一个div,右边信息一个div,再在右边的div中进行div切割,切割成列表,我的代码如下:
 <asp:DataList ID="cominfr" runat="server" Width="100%">
            <ItemTemplate>
                <div class="infrlist">
                    <div class="infimg">
                        <asp:Image ID="Image1" runat="server" ImageUrl='<%#comimgurl(Eval("image").ToString())%>' />
                    </div>
                    <div class="textlist">
                        <div class="lilist">
                            <div class="lisname">
                                企业名称:</div>
                            <div class="lisitem">
                                <%#gettitle(Eval("title").ToString())%>
                            </div>
                        </div>
                        <div class="lilist">
                            <div class="lisname">
                                公司地址:</div>
                            <div class="lisitem">
                                <%#settext(Eval("ti").ToString())%>
                            </div>
                        </div>
                        <div class="lilist">
                            <div class="lisname">
                                联 系 人:</div>
                            <div class="lisitem">
                                <%#settext(Eval("man").ToString())%>
                            </div>
                        </div>
                        <div class="lilist">
                            <div class="lisname">
                                联系电话:</div>
                            <div class="lisitem">
                                <%#settext(Eval("tel").ToString())%>
                            </div>
                        </div>
                        <div class="lilist">
                            <div class="lisname">
                                手机短号:</div>
                            <div class="lisitem">
                                暂无</div>
                        </div>
                        <div class="lilist">
                            <div class="lisname">
                                传真号码:</div>
                            <div class="lisitem">
                                <%#settext(Eval("fax").ToString())%>
                            </div>
                        </div>
                        <div class="lilist">
                            <div class="lisname">
                                公司主页:</div>
                            <div class="lisitem">
                                <a href ="<%#Eval("comurl")%>"><%#Eval("comurl")%></a>
                            </div>
                        </div>
                    </div>
                </div>
            </ItemTemplate>
        </asp:DataList>


分页功能与pagedatasource,如:
 private void pldatalist() 
    {
        string sqltext = "你的sql语句";
        PagedDataSource pds = new PagedDataSource();DataTable dt = new DataTable();
        dt = sqldatacontrol.gettabeldata(sqltext);//我的sql查询方法
        pds.DataSource = dt.DefaultView;
        pds.AllowPaging = true;
        pds.PageSize = 5;//每页显示5条记录
        if (dt.Rows.Count > 0) { fenyei.Visible = true; } else { fenyei.Visible = false; }
        allpage.Text = pds.PageCount.ToString();
        pds.CurrentPageIndex = Convert.ToInt32(curindex.Value)-1;//把现在页码数赋给CurrentPageIndex
        pldl.DataSource = pds;
        pldl.DataBind();
    } --------------------编程问答-------------------- 晕  楼主还健在不?? 都两年多了 --------------------编程问答-------------------- 是呀 楼上的不提醒 还没注意呢  --------------------编程问答-------------------- 楼主在地震中丧生了

默哀... --------------------编程问答-------------------- 哎  惨 --------------------编程问答-------------------- UP --------------------编程问答-------------------- 2年了---这还要高手来写吗? --------------------编程问答-------------------- 够狠, 这种帖子 还能存在于世。。。。。。。。  --------------------编程问答-------------------- 帮顶! --------------------编程问答-------------------- 过来拿点分 --------------------编程问答-------------------- 这原来是两年前的帖子啊.......
补充:.NET技术 ,  ASP.NET
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,