在将数据表绑定到Asp.Net中的GridView时出现问题 [英] Problem occured in Binding DataTable to the GridView in Asp.Net
本文介绍了在将数据表绑定到Asp.Net中的GridView时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用asp.net 3.5中的GridView,我想在我的网格中显示列(Hotelimage,Address,URL).为此,我在grdvHotels.aspx.cs文件中编写了以下代码.
I am working with GridView in asp.net 3.5,i want to display the columns(Hotelimage,Address,URL)in my grid. For this i wrote the following code in my grdvHotels.aspx.cs file.
Page_Load
{
grdvHotels.DataBind();
}
DataTable GetData()
{
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn("Hotel", typeof(string)));
dt.Columns.Add(new DataColumn("Address", typeof(string)));
dt.Columns.Add(new DataColumn("URL", typeof(string)));
DataRow dr = dt.NewRow();
dr["Hotel"] = ResolveUrl("~/IMAGES/image1.jpg");
dr["Address"] = "Bangalore";
dr["URL"] = ResolveUrl("www.yahoo.com");
dt.Rows.Add(dr);
}
来源
Source
<asp:GridView ID="grdHotels" runat="server"
CellSpacing="3" AutoGenerateColumns="False" DataSource='<%#GetData() %>'>
<Columns>
<asp:ImageField DataImageUrlField="HOTEL"></asp:ImageField>
<asp:BoundField HeaderText="Address" DataField="Address" />
<asp:BoundField HeaderText="URL" DataField="URL" />
</Columns>
<SelectedRowStyle ForeColor="White" Font-Bold="true" BackColor="Aqua" ></SelectedRowStyle>
</asp:GridView>
-------------------------------------------------- ----
在运行应用程序时遇到错误.我没有得到解决这个问题的方法.添加我的代码是否需要任何东西.请给解决方案.
谢谢
Raj
------------------------------------------------------
While running the application error encountered. I didn''t get the solution for this problem. Is anything required to add my code.Plz give the solution.
Thanks
Raj
推荐答案
我认为此链接 [ ^ ]将帮助您
i think this link [^] will help you
这篇关于在将数据表绑定到Asp.Net中的GridView时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文