|
 |
aspx_beginners thread: Further ASP - ASP.NET questions
Message #1 by "Dan McKinnon" <mddonna@q...> on Sat, 4 May 2002 00:01:03
|
|
Hi -
Someone said on this forum the other day: The things that were hard in
ASP are easy in ASP.NET, and the things that were easy are hard. amen
I can access my sql database no problem, but I don't know how to
manipulate the data and columns like I could in regular ASP like this:
Response.Write "<table><tr><td>" & myRS("text") & "</td></tr></table>"
With .NET I create the connection string, sql string, dataset,
sqlconnection, dataAdapter, dataView, and dataGrid. But how does one get
control over the dataGrid? It seems like an all or nothing scenario. What
if I want to add an id attribute to a <td> when the datagrid is
dynamically generated by .NET? Or do something else to the display, like
add cellspacing or font attributes? I have two .NET books, and neither
seems to address this.
Another question:
I have a datetime field in sql server that I access from a Web page. I
don't want to display the time, only the date, but it seems like I either
show both the date and time or nothing. I suppose I could capture the
whole thing and do a string manipulation after converting the datetime to
a string, but this seems awfully involved. Does anyone know how to do
this?
Thank you,
Dan
Message #2 by "Minh T. Nguyen" <nguyentriminh@y...> on Fri, 3 May 2002 16:08:32 -0700
|
|
Hey Dan,
As for your first question, you can tell ASP.NET not to
autogenerate all your columns and this way you can define them by hand.
Here's an example:
<asp:DataGrid id="PeopleTable" runat="server"
AutoGenerateColumns="False">
<HeaderStyle Font-Bold="True" BackColor="#E0E0E0"></HeaderStyle>
<Columns>
<asp:BoundColumn DataField="strEmail" HeaderText="Email
Address">
</asp:BoundColumn>
<asp:BoundColumn DataField="strName" HeaderText="Name">
</asp:BoundColumn>
</Columns>
</asp:DataGrid>
As you can see I tell the DataGrid not to automatically generate
the columns. Then I can specify the columns manually with BoundColumn
and so on. On top of that I can specify cell spacing, color font
attributes all with properties such as Font-Color, BackColor and as well
as the order by which the columns appear as you can see in this example.
There is an entire list of attributes that you can put into
asp:BoundColumn or asp:TemplateColumn and so on.
As for your second question, on
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/h
tml/frlrfsystemglobalizationdatetimeformatinfoclasstopic.asp there is a
list of date format codes you can use to just display the date. In
particular your asp:BoudColumn should look like this:
<asp:BoundColumn DataField="myDateField" HeaderText="Date of
Birth" DataFormatString="{0:d}">
</asp:BoundColumn>
d stands for short date format. There is the entire list of
codes such as I haven't compiled this code myself, but it should work
for you.
However, I do find myself sometimes generate columns on the fly
on the server side just to easily display certain strings that would be
harder to express with datagrid-specific HTML tags.
Hope it helps,
Minh.
-----Original Message-----
From: Dan McKinnon [mailto:mddonna@q...]
Sent: Saturday, May 04, 2002 12:01 AM
To: aspx_beginners
Subject: [aspx_beginners] Further ASP - ASP.NET questions
Hi -
Someone said on this forum the other day: The things that were hard in
ASP are easy in ASP.NET, and the things that were easy are hard. amen
I can access my sql database no problem, but I don't know how to
manipulate the data and columns like I could in regular ASP like this:
Response.Write "<table><tr><td>" & myRS("text") & "</td></tr></table>"
With .NET I create the connection string, sql string, dataset,
sqlconnection, dataAdapter, dataView, and dataGrid. But how does one get
control over the dataGrid? It seems like an all or nothing scenario.
What
if I want to add an id attribute to a <td> when the datagrid is
dynamically generated by .NET? Or do something else to the display, like
add cellspacing or font attributes? I have two .NET books, and neither
seems to address this.
Another question:
I have a datetime field in sql server that I access from a Web page. I
don't want to display the time, only the date, but it seems like I
either
show both the date and time or nothing. I suppose I could capture the
whole thing and do a string manipulation after converting the datetime
to
a string, but this seems awfully involved. Does anyone know how to do
this?
Thank you,
Dan
Message #3 by "Curtner, Lynn" <lynn.curtner@p...> on Mon, 6 May 2002 08:04:47 -0500
|
|
In reply to your first question, and I'm probably misunderstanding what you're trying to do, you can manipulate the datagrid
programmatically in the codebehind file. E.g., here's some code that configures a datagrid named ReportDataGrid...
private void ConfigureDataGrid()
{
ReportDataGrid.Font.Name = "Arial";
ReportDataGrid.Font.Size = FontUnit.Point(10);
ReportDataGrid.BorderStyle = BorderStyle.Solid;
ReportDataGrid.BorderWidth = 2;
ReportDataGrid.BorderColor = Color.Gray;
ReportDataGrid.BackColor = Color.Silver;
ReportDataGrid.CellSpacing = 2;
ReportDataGrid.HeaderStyle.Font.Bold = true;
ReportDataGrid.HeaderStyle.Font.Size = FontUnit.Point(10);
ReportDataGrid.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
ReportDataGrid.HeaderStyle.ForeColor = Color.White;
ReportDataGrid.HeaderStyle.BackColor = Color.Teal;
for (int i = 0; i < ReportDataGrid.Items.Count; i++)
{
for (int j = 0; j < ReportDataGrid.Items[i].Cells.Count; j++)
{
ReportDataGrid.Items[i].Cells[j].Wrap = false;
}
}
}
TPWH,
Lynn Curtner
> ----------
> From: Minh T. Nguyen[SMTP:nguyentriminh@y...]
> Reply To: aspx_beginners
> Sent: Friday, May 03, 2002 6:08 PM
> To: aspx_beginners
> Subject: [aspx_beginners] RE: Further ASP - ASP.NET questions
>
> Hey Dan,
>
> As for your first question, you can tell ASP.NET not to
> autogenerate all your columns and this way you can define them by hand.
> Here's an example:
>
> <asp:DataGrid id="PeopleTable" runat="server"
> AutoGenerateColumns="False">
> <HeaderStyle Font-Bold="True" BackColor="#E0E0E0"></HeaderStyle>
> <Columns>
> <asp:BoundColumn DataField="strEmail" HeaderText="Email
> Address">
> </asp:BoundColumn>
> <asp:BoundColumn DataField="strName" HeaderText="Name">
> </asp:BoundColumn>
> </Columns>
> </asp:DataGrid>
>
> As you can see I tell the DataGrid not to automatically generate
> the columns. Then I can specify the columns manually with BoundColumn
> and so on. On top of that I can specify cell spacing, color font
> attributes all with properties such as Font-Color, BackColor and as well
> as the order by which the columns appear as you can see in this example.
> There is an entire list of attributes that you can put into
> asp:BoundColumn or asp:TemplateColumn and so on.
>
> As for your second question, on
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/h
> tml/frlrfsystemglobalizationdatetimeformatinfoclasstopic.asp there is a
> list of date format codes you can use to just display the date. In
> particular your asp:BoudColumn should look like this:
>
> <asp:BoundColumn DataField="myDateField" HeaderText="Date of
> Birth" DataFormatString="{0:d}">
> </asp:BoundColumn>
>
> d stands for short date format. There is the entire list of
> codes such as I haven't compiled this code myself, but it should work
> for you.
>
> However, I do find myself sometimes generate columns on the fly
> on the server side just to easily display certain strings that would be
> harder to express with datagrid-specific HTML tags.
>
> Hope it helps,
> Minh.
>
> -----Original Message-----
> From: Dan McKinnon [mailto:mddonna@q...]
> Sent: Saturday, May 04, 2002 12:01 AM
> To: aspx_beginners
> Subject: [aspx_beginners] Further ASP - ASP.NET questions
>
>
> Hi -
>
> Someone said on this forum the other day: The things that were hard in
> ASP are easy in ASP.NET, and the things that were easy are hard. amen
>
> I can access my sql database no problem, but I don't know how to
> manipulate the data and columns like I could in regular ASP like this:
>
> Response.Write "<table><tr><td>" & myRS("text") & "</td></tr></table>"
>
> With .NET I create the connection string, sql string, dataset,
> sqlconnection, dataAdapter, dataView, and dataGrid. But how does one get
>
> control over the dataGrid? It seems like an all or nothing scenario.>
> What
> if I want to add an id attribute to a <td> when the datagrid is
> dynamically generated by .NET? Or do something else to the display, like
>
> add cellspacing or font attributes? I have two .NET books, and neither
> seems to address this.
>
> Another question:
> I have a datetime field in sql server that I access from a Web page. I
> don't want to display the time, only the date, but it seems like I
> either
> show both the date and time or nothing. I suppose I could capture the
> whole thing and do a string manipulation after converting the datetime
> to
> a string, but this seems awfully involved. Does anyone know how to do
> this?
>
> Thank you,
> Dan
>
>
>
|
|
 |