adding Cutom columns from a business collection object

N

Nabeel Moeen

Hello all,
I'm new to ASP.NET and the .NET framework. I've been trying to get the
WebControls.DataGrid to work but havent been successful in acheiving the
desired results.
What i need to do is, set the DataSource for the grid to some business
collection object (from my application framework). it successfully
autogenerates the columns and the data is displayed.
But i want to define which columsn should appear rather than displaying all
the columns by default.
And all the code for the page is written in the ".cs" file so i the ASP
examples from MSDN havent been of much help.
Any suggestions or references are welcome.
Thanx
 
P

Pawan

Hullo Dear,
When you are declaring your datagrid control, set its
AutoGenerateColumn property to AutoGenerateColumns="False"
and then use <Columns> Tag to append <asp:BoundColumn> ..
Below you can find an illustration .. In case any problem,
gimme a shout or buzz me ..


<asp:datagrid id="dgContacts" runat="server"
OnPageIndexChanged="Page_Change" PagerStyle-
Mode="NumericPages" PageSize="5" AllowPaging="True"
AllowSorting="True" Width="100%"
AutoGenerateColumns="False" DataKeyField="ContactID">

<AlternatingItemStyle ssClass="row"></AlternatingItemStyle>
<SelectedItemStyle Font-Bold="True"></SelectedItemStyle>
<HeaderStyle CssClass="toprow"></HeaderStyle>

<Columns>

<asp:HyperLinkColumn DataNavigateUrlField="UserID"
DataNavigateUrlFormatString="ContactLists.ascx?ID={0}"
DataTextField="UserID" HeaderText="User
ID"></asp:HyperLinkColumn>

<asp:BoundColumn DataField="ContactFirstName"
HeaderText="First Name" ItemStyle-
Wrap="False"></asp:BoundColumn>

<asp:BoundColumn DataField="ContactLastName"
HeaderText="Last Name" ItemStyle-
Wrap="False"></asp:BoundColumn>

<asp:BoundColumn DataField="CompName" HeaderText="Company"
ItemStyle-Wrap="False"></asp:BoundColumn>

<asp:BoundColumn DataField="ContactWeb" HeaderText="Web
URL" ItemStyle-Wrap="False"></asp:BoundColumn>

<asp:BoundColumn DataField="ContactPassportNo"
HeaderText="Passport Number" ItemStyle-
Wrap="False"></asp:BoundColumn>

</Columns>
<PagerStyle Mode="NumericPages"></PagerStyle>
</asp:datagrid>


Keep Good n stay blessed.


Pawan
 
N

Nabeel Moeen

:D thanx for the information..
this code appears to be in ASP ...
i'll see if i can translate it to C# .. or dig out the relevant
information..

will let u know of the outcome..
(i'd appreciate it if u could send some C# specific code as well )

thanx once again
 
N

Nabeel Moeen

thanx a lot friend..
got it working

Pawan said:
Hullo Dear,
When you are declaring your datagrid control, set its
AutoGenerateColumn property to AutoGenerateColumns="False"
and then use <Columns> Tag to append <asp:BoundColumn> ..
Below you can find an illustration .. In case any problem,
gimme a shout or buzz me ..


<asp:datagrid id="dgContacts" runat="server"
OnPageIndexChanged="Page_Change" PagerStyle-
Mode="NumericPages" PageSize="5" AllowPaging="True"
AllowSorting="True" Width="100%"
AutoGenerateColumns="False" DataKeyField="ContactID">

<AlternatingItemStyle ssClass="row"></AlternatingItemStyle>
<SelectedItemStyle Font-Bold="True"></SelectedItemStyle>
<HeaderStyle CssClass="toprow"></HeaderStyle>

<Columns>

<asp:HyperLinkColumn DataNavigateUrlField="UserID"
DataNavigateUrlFormatString="ContactLists.ascx?ID={0}"
DataTextField="UserID" HeaderText="User
ID"></asp:HyperLinkColumn>

<asp:BoundColumn DataField="ContactFirstName"
HeaderText="First Name" ItemStyle-
Wrap="False"></asp:BoundColumn>

<asp:BoundColumn DataField="ContactLastName"
HeaderText="Last Name" ItemStyle-
Wrap="False"></asp:BoundColumn>

<asp:BoundColumn DataField="CompName" HeaderText="Company"
ItemStyle-Wrap="False"></asp:BoundColumn>

<asp:BoundColumn DataField="ContactWeb" HeaderText="Web
URL" ItemStyle-Wrap="False"></asp:BoundColumn>

<asp:BoundColumn DataField="ContactPassportNo"
HeaderText="Passport Number" ItemStyle-
Wrap="False"></asp:BoundColumn>

</Columns>
<PagerStyle Mode="NumericPages"></PagerStyle>
</asp:datagrid>


Keep Good n stay blessed.


Pawan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top