brgdotnet
asked on
ASP:DataGrid and how to bind to a BoundColumn
I will be required to start working with ASP:DataGrid controls.(Not GridView). I want to create a very basic DataGrid with one or two columns of Data using data bound columns. Below I have create a basic ASP:DataGrid. I bind the data source to my Grid using
some simple data set data I created in C#. It works great however I am gettng the same column duplicated twice? How can change
the code so that the data source is one column which maps to by bound data column below in my asp markup. DataField ="Name"?
<asp:Content runat="server" ID="FeaturedContent" ContentPlaceHolderID="Feat uredConten t">
<ASP:DataGrid id="MyDataGrid" runat="server" Width="700px" EnableViewState="False">
<Columns>
<asp:BoundColumn DataField="Name" ReadOnly="True" HeaderText="Name">
<HeaderStyle Font-Bold="True" HorizontalAlign="Center">< /ItemStyle >
</asp:BoundColumn>
</Columns>
</asp:DataGrid>
</asp:Content>
-------------------------- -
namespace WebApplication1
{
public partial class _Default : Page
{
DataSet ds = new DataSet();
DataTable dt = new DataTable();
dt.Columns.Add("Name", Type.GetType("System.Strin g"));
dt.Rows.Add(new object[] {"James Bawn"});
ds.Tables.Add(dt);
MyDataGrid.DataSource=dt;
MyDataGrid.DataBind();
some simple data set data I created in C#. It works great however I am gettng the same column duplicated twice? How can change
the code so that the data source is one column which maps to by bound data column below in my asp markup. DataField ="Name"?
<asp:Content runat="server" ID="FeaturedContent" ContentPlaceHolderID="Feat
<ASP:DataGrid id="MyDataGrid" runat="server" Width="700px" EnableViewState="False">
<Columns>
<asp:BoundColumn DataField="Name" ReadOnly="True" HeaderText="Name">
<HeaderStyle Font-Bold="True" HorizontalAlign="Center"><
</asp:BoundColumn>
</Columns>
</asp:DataGrid>
</asp:Content>
--------------------------
namespace WebApplication1
{
public partial class _Default : Page
{
DataSet ds = new DataSet();
DataTable dt = new DataTable();
dt.Columns.Add("Name", Type.GetType("System.Strin
dt.Rows.Add(new object[] {"James Bawn"});
ds.Tables.Add(dt);
MyDataGrid.DataSource=dt;
MyDataGrid.DataBind();
ASKER
Pawan I am mot using a GridView control sir. I am using an asp.net DataGrid control.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
AutoGenerate columns is not in my markup. It looks like you posted in some other code Pawan, and not the code I posted.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks Pawan for the help. I won't be able to close this question out until tomorrow. I appreciate your help.
Closing question is not a problem. Your problem should be fixed. :)
Regards,
Pawan
Regards,
Pawan
ASKER
Thank you Pawan, you are truly great!!
Open in new window