0

大家好,我的问题是从 sql 中检索数据并显示在标签中,但是一旦我无法分隔所有数据中的数据行,所有数据都显示在一行中请帮助

<asp:GridView ID="grid_advertise_2" runat="server" AllowPaging="True" AutoGenerateColumns="False"
                GridLines="None" OnPageIndexChanging="GridView2_PageIndexChanging" PageSize="1"
                ShowHeader="False" OnSelectedIndexChanged="GridView2_SelectedIndexChanged">
    <Columns>
        <asp:TemplateField>
            <ItemTemplate>
                <tr>
                    <td id="advertise_2">
                        <asp:Label ID="lbl_advertise_2"
                                   runat="server"
                                   Font-Names="Tahoma"
                                   Font-Size="12pt"
                                   ForeColor="black"
                                   Text='<%# Bind("TitleEn") %>'/>
                    </td>
                 </tr>
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>

在服务器代码中

protected void Page_Load(object sender, EventArgs e)
{
    string Path = "Article.aspx";
    Session.Add("Path", Path.ToString());
    if (!IsPostBack)
    {
        this.BindGridadvertise1();
        this.BindGridadvertise2();
    }
}

private void BindGridadvertise1()
{
    myConnection c = new myConnection();
    SqlDataAdapter da = 
      new SqlDataAdapter("select * from TblArticleWishka where ID >= 0 ", c.Cnn);
    DataSet ds = new DataSet();
    da.Fill(ds);
    grid_advertise_1.DataSource = ds.Tables[0];
    grid_advertise_1.DataBind();
}
4

1 回答 1

0

嗨,伙计们,我做到了,我通过创建新的销售并给他们 cssclass` int j = 0 来做到这一点;

protected void grid_advertise_1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (j<=1)
   {
        myConnection c = new myConnection();
        SqlDataAdapter da = new SqlDataAdapter("select * from TblArticleWishka where ID>=0 ", c.Cnn);
        DataSet ds = new DataSet();
        da.Fill(ds);
        int i = 1;
        foreach (DataRow dr in ds.Tables[0].Rows)
        {

            i++;
            TableCell a = new TableCell();
            a.CssClass = "advertise_1_" + i + "";
            a.Text = (string)dr["TitleEn"];
            e.Row.Cells.Add(a);
            a.DataBind();
        }
        j++;
   }
}`
于 2013-08-06T10:38:38.377 回答