嗨,每一个我的问题都是从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();
}
答案 0 :(得分: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++;
}
}`