我有一個問題,在不同的列顯示gridview中的數據,但數據顯示在一個列中。網格視圖列arragement
設計
<asp:GridView ID="GridView1" runat="server" class="international_news" AutoGenerateColumns="False" DataKeyNames="news_id" onrowcommand="GridView1_RowCommand">
<Columns>
<asp:BoundField DataField="news_id"/>
<asp:BoundField DataField="news_title"/>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CommandName="ReadMore" CommandArgument='<%#Eval("news_id")%>'>
Read More
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
代碼背後
if (!this.IsPostBack)
{
dt.Columns.AddRange(new DataColumn[2] { new DataColumn("news_id", typeof(string)),
new DataColumn("news_title", typeof(string))});
while (dr.Read())
{
if (dr[1].ToString() != "yes")
{
dt.Rows.Add(dr[0].ToString());
dt.Rows.Add(dr[1].ToString());
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
您能舉一個預期結果和實際結果的例子嗎? –