By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,717 Members | 2,069 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,717 IT Pros & Developers. It's quick & easy.

Datagrid example

P: n/a
Can someone write some VB.Net example code for me that does this:

1) Creates a gridview control with the results of a SQL stored procedure
that has 1 parameter (text)

2) Adds an extra column that displays the result of a VB.Net function that
uses a value from an existing column

I have spent 4 hours trying to do this after Googling for examples... There
are many new concepts that I haven't had much experience with...

Jun 27 '08 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Hi Mark,

Regarding on the questions you mentioned, here are some of my suggestion:

1) Creates a gridview control with the results of a SQL stored procedure
that has 1 parameter (text)
==============================
I'm wondering what's the difficulty you encounter here. To display the
results, I think it include two parts:

** first, you need to execute the SQSL stored procedure and get the
returned resultset(need to supply the parameter)

**second, you should bind the resultset to the gridview control

for calling stored procedure in ASP.NET, here are many reference:

#How to call SQL Server stored procedures in ASP.NET by using Visual Basic
.NET
http://support.microsoft.com/kb/306574

And you can also use SQL Datasource control in ASP.NET 2.0 which make
databinding/query more convenient:

#SQLDataSource Control
http://www.learn-asp.net/ASPTutorial...ceControl.aspx

http://www.asp.net/LEARN/data-access...ial-47-cs.aspx
For bind resultset to Gridview, I think it's quite straightforward:

** if you query the database programmtically, you need to assign the result
set(datatable or datareader) to Gridview and call DataBind method. e.g.

Gridview1.DataSource = [returned data resultset];
Gridview1.DataBind();

Or you can use SqlDataSource control(refer to the aritlce I mentioned
above).

2) Adds an extra column that displays the result of a VB.Net function that
uses a value from an existing column
================================
I think the natural approach is adding a template column which use other
existing column's datafield to compute the certain value you want. Here are
some reference about using template column:

#Using TemplateFields in the GridView Control
http://www.asp.net/learn/data-access...ial-12-cs.aspx

#GridView Examples for ASP.NET 2.0: Working with TemplateFields
http://msdn.microsoft.com/en-us/library/aa479353.aspx
And here is a simple example. I use a gridview to display data through a
SqlDataSource control and it contains two columns by default. I add an
additional template column which use a helper function(to calculate the
display value depend on the two existing column value):
>>>>>>>>>>aspx template>>>>>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:testdbConnectionString
%>"
SelectCommand="SELECT [id], [name] FROM
[numtable]"></asp:SqlDataSource>
<br />
<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False"
DataKeyNames="id" DataSourceID="SqlDataSource1">
<Columns>
<asp:BoundField DataField="id" HeaderText="id"
ReadOnly="True"
SortExpression="id" />
<asp:BoundField DataField="name" HeaderText="name"
SortExpression="name" />
<asp:TemplateField>
<ItemTemplate>
<%# MyFunction(Eval("id"), Eval("name")) %>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
>>>>>>>>code behind>>>>>>>>>>>>>>>
protected string MyFunction(object id, object name)
{
return id.ToString() + "|" + name.ToString();
}
>>>>>>>>>>>>>>>>>>>>>>
In addition, if you do not have much ASP.NET programming experience, I
would suggest you have a look at the tutorials on ASP.NET offical site:

http://www.asp.net/learn/

and since you're developing data access application, the "Data Access
tutorial" is especially important for you:

http://www.asp.net/learn/data-access/

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
>From: "Mark B" <no**@none.com>
Subject: Datagrid example
Date: Fri, 30 May 2008 13:10:32 +1200
>
Can someone write some VB.Net example code for me that does this:

1) Creates a gridview control with the results of a SQL stored procedure
that has 1 parameter (text)

2) Adds an extra column that displays the result of a VB.Net function that
uses a value from an existing column

I have spent 4 hours trying to do this after Googling for examples...
There
>are many new concepts that I haven't had much experience with...

Jun 27 '08 #2

P: n/a
Hi Mark,

Do you have any further questions on this or does the suggestion in my last
reply help you some?

Sincerely,

Steven Cheng
Microsoft MSDN Online Support Lead
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

--------------------
>From: st*****@online.microsoft.com (Steven Cheng [MSFT])
Organization: Microsoft
Date: Fri, 30 May 2008 03:52:12 GMT
Subject: RE: Datagrid example
>
Hi Mark,

Regarding on the questions you mentioned, here are some of my suggestion:

1) Creates a gridview control with the results of a SQL stored procedure
that has 1 parameter (text)
==============================
I'm wondering what's the difficulty you encounter here. To display the
results, I think it include two parts:

** first, you need to execute the SQSL stored procedure and get the
returned resultset(need to supply the parameter)

**second, you should bind the resultset to the gridview control

for calling stored procedure in ASP.NET, here are many reference:

#How to call SQL Server stored procedures in ASP.NET by using Visual Basic
.NET
http://support.microsoft.com/kb/306574

And you can also use SQL Datasource control in ASP.NET 2.0 which make
databinding/query more convenient:

#SQLDataSource Control
http://www.learn-asp.net/ASPTutorial...ceControl.aspx

http://www.asp.net/LEARN/data-access...ial-47-cs.aspx
For bind resultset to Gridview, I think it's quite straightforward:

** if you query the database programmtically, you need to assign the
result
>set(datatable or datareader) to Gridview and call DataBind method. e.g.

Gridview1.DataSource = [returned data resultset];
Gridview1.DataBind();

Or you can use SqlDataSource control(refer to the aritlce I mentioned
above).

2) Adds an extra column that displays the result of a VB.Net function that
uses a value from an existing column
================================
I think the natural approach is adding a template column which use other
existing column's datafield to compute the certain value you want. Here
are
>some reference about using template column:

#Using TemplateFields in the GridView Control
http://www.asp.net/learn/data-access...ial-12-cs.aspx

#GridView Examples for ASP.NET 2.0: Working with TemplateFields
http://msdn.microsoft.com/en-us/library/aa479353.aspx
And here is a simple example. I use a gridview to display data through a
SqlDataSource control and it contains two columns by default. I add an
additional template column which use a helper function(to calculate the
display value depend on the two existing column value):
>>>>>>>>>>>aspx template>>>>>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:testdbConnectionString
%>"
SelectCommand="SELECT [id], [name] FROM
[numtable]"></asp:SqlDataSource>
<br />
<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False"
DataKeyNames="id" DataSourceID="SqlDataSource1">
<Columns>
<asp:BoundField DataField="id" HeaderText="id"
ReadOnly="True"
SortExpression="id" />
<asp:BoundField DataField="name" HeaderText="name"
SortExpression="name" />
<asp:TemplateField>
<ItemTemplate>
<%# MyFunction(Eval("id"), Eval("name")) %>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
>>>>>>>>>code behind>>>>>>>>>>>>>>>
protected string MyFunction(object id, object name)
{
return id.ToString() + "|" + name.ToString();
}
>>>>>>>>>>>>>>>>>>>>>>>

In addition, if you do not have much ASP.NET programming experience, I
would suggest you have a look at the tutorials on ASP.NET offical site:

http://www.asp.net/learn/

and since you're developing data access application, the "Data Access
tutorial" is especially important for you:

http://www.asp.net/learn/data-access/

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

================================================= =
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ault.aspx#noti
f
>ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
================================================= =
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
>>From: "Mark B" <no**@none.com>
Subject: Datagrid example
Date: Fri, 30 May 2008 13:10:32 +1200
>>
Can someone write some VB.Net example code for me that does this:

1) Creates a gridview control with the results of a SQL stored procedure
that has 1 parameter (text)

2) Adds an extra column that displays the result of a VB.Net function
that
>>uses a value from an existing column

I have spent 4 hours trying to do this after Googling for examples...
There
>>are many new concepts that I haven't had much experience with...


Jun 27 '08 #3

P: n/a
Thanks Steven. I am planning to start that reading you suggested right now.

Thanks for the offer of answering any further questions I have.

"Steven Cheng [MSFT]" <st*****@online.microsoft.comwrote in message
news:Hf**************@TK2MSFTNGHUB02.phx.gbl...
Hi Mark,

Do you have any further questions on this or does the suggestion in my
last
reply help you some?

Sincerely,

Steven Cheng
Microsoft MSDN Online Support Lead
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

--------------------
>>From: st*****@online.microsoft.com (Steven Cheng [MSFT])
Organization: Microsoft
Date: Fri, 30 May 2008 03:52:12 GMT
Subject: RE: Datagrid example
>>
Hi Mark,

Regarding on the questions you mentioned, here are some of my suggestion:

1) Creates a gridview control with the results of a SQL stored procedure
that has 1 parameter (text)
==============================
I'm wondering what's the difficulty you encounter here. To display the
results, I think it include two parts:

** first, you need to execute the SQSL stored procedure and get the
returned resultset(need to supply the parameter)

**second, you should bind the resultset to the gridview control

for calling stored procedure in ASP.NET, here are many reference:

#How to call SQL Server stored procedures in ASP.NET by using Visual Basic
.NET
http://support.microsoft.com/kb/306574

And you can also use SQL Datasource control in ASP.NET 2.0 which make
databinding/query more convenient:

#SQLDataSource Control
http://www.learn-asp.net/ASPTutorial...ceControl.aspx

http://www.asp.net/LEARN/data-access...ial-47-cs.aspx
For bind resultset to Gridview, I think it's quite straightforward:

** if you query the database programmtically, you need to assign the
result
>>set(datatable or datareader) to Gridview and call DataBind method. e.g.

Gridview1.DataSource = [returned data resultset];
Gridview1.DataBind();

Or you can use SqlDataSource control(refer to the aritlce I mentioned
above).

2) Adds an extra column that displays the result of a VB.Net function that
uses a value from an existing column
================================
I think the natural approach is adding a template column which use other
existing column's datafield to compute the certain value you want. Here
are
>>some reference about using template column:

#Using TemplateFields in the GridView Control
http://www.asp.net/learn/data-access...ial-12-cs.aspx

#GridView Examples for ASP.NET 2.0: Working with TemplateFields
http://msdn.microsoft.com/en-us/library/aa479353.aspx
And here is a simple example. I use a gridview to display data through a
SqlDataSource control and it contains two columns by default. I add an
additional template column which use a helper function(to calculate the
display value depend on the two existing column value):
>>>>>>>>>>>>aspx template>>>>>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:testdbConnectionString
%>"
SelectCommand="SELECT [id], [name] FROM
[numtable]"></asp:SqlDataSource>
<br />
<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False"
DataKeyNames="id" DataSourceID="SqlDataSource1">
<Columns>
<asp:BoundField DataField="id" HeaderText="id"
ReadOnly="True"
SortExpression="id" />
<asp:BoundField DataField="name" HeaderText="name"
SortExpression="name" />
<asp:TemplateField>
<ItemTemplate>
<%# MyFunction(Eval("id"), Eval("name")) %>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
>>>>>>>>>>code behind>>>>>>>>>>>>>>>
protected string MyFunction(object id, object name)
{
return id.ToString() + "|" + name.ToString();
}
>>>>>>>>>>>>>>>>>>>>>>>>

In addition, if you do not have much ASP.NET programming experience, I
would suggest you have a look at the tutorials on ASP.NET offical site:

http://www.asp.net/learn/

and since you're developing data access application, the "Data Access
tutorial" is especially important for you:

http://www.asp.net/learn/data-access/

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

================================================ ==
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ault.aspx#noti
f
>>ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
================================================ ==
This posting is provided "AS IS" with no warranties, and confers no
rights.

--------------------
>>>From: "Mark B" <no**@none.com>
Subject: Datagrid example
Date: Fri, 30 May 2008 13:10:32 +1200
>>>
Can someone write some VB.Net example code for me that does this:

1) Creates a gridview control with the results of a SQL stored procedure
that has 1 parameter (text)

2) Adds an extra column that displays the result of a VB.Net function
that
>>>uses a value from an existing column

I have spent 4 hours trying to do this after Googling for examples...
There
>>>are many new concepts that I haven't had much experience with...


Jun 27 '08 #4

P: n/a
When I drag the Datagrid control over to the design view of an aspx page, it
prompts me for many things like datasource, fields etc. After I fill all of
these in I notice it creates quite a lot of html:

e.g.

<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:MyDBConnectionString %>"
SelectCommand="uspGroupsDataGridSource"
SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:QueryStringParameter DefaultValue="Group1"
Name="EnterMasterGroupName"
QueryStringField="SelectedGroup" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AllowSorting="True" AutoGenerateColumns="False" CellPadding="4"
DataSourceID="SqlDataSource1" ForeColor="#333333" GridLines="None">
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White"
/>
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<Columns>
<asp:BoundField DataField="GroupName" HeaderText="GroupName"
SortExpression="GroupName" />
<asp:BoundField DataField="AverageSales30Days"
HeaderText="AverageSales30Days"
ReadOnly="True" SortExpression="AverageSales30Days" />
<asp:BoundField DataField="AverageGrade30Days"
HeaderText="AverageGrade30Days"
ReadOnly="True" SortExpression="AverageGrade30Days" />
<asp:BoundField DataField="AverageSales6Months"
HeaderText="AverageSales6Months"
ReadOnly="True" SortExpression="AverageSales6Months" />
<asp:BoundField DataField="AverageGrade6Months"
HeaderText="AverageGrade6Months" ReadOnly="True"
SortExpression="AverageGrade6Months" />
<asp:BoundField DataField="AverageSales12Months"
HeaderText="AverageSales12Months"
ReadOnly="True" SortExpression="AverageSales12Months" />
<asp:BoundField DataField="AverageGrade12Months"
HeaderText="AverageGrade12Months" ReadOnly="True"
SortExpression="AverageGrade12Months" />
</Columns>
<PagerStyle BackColor="#284775" ForeColor="White"
HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True"
ForeColor="#333333" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White"
/>
<EditRowStyle BackColor="#999999" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
</asp:GridView>


So my question is, if if follow the example below and type in VB.Net code,
will this conflict with what I already have with the HTML? Which one will
take precedence?

Do I need to delete some of the HTML?


"Mark B" <no**@none.comwrote in message
news:uB*************@TK2MSFTNGP05.phx.gbl...
Thanks Steven. I am planning to start that reading you suggested right
now.

Thanks for the offer of answering any further questions I have.

"Steven Cheng [MSFT]" <st*****@online.microsoft.comwrote in message
news:Hf**************@TK2MSFTNGHUB02.phx.gbl...
>Hi Mark,

Do you have any further questions on this or does the suggestion in my
last
reply help you some?

Sincerely,

Steven Cheng
Microsoft MSDN Online Support Lead
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you.
Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

================================================= =
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

--------------------
>>>From: st*****@online.microsoft.com (Steven Cheng [MSFT])
Organization: Microsoft
Date: Fri, 30 May 2008 03:52:12 GMT
Subject: RE: Datagrid example
>>>
Hi Mark,

Regarding on the questions you mentioned, here are some of my suggestion:

1) Creates a gridview control with the results of a SQL stored procedure
that has 1 parameter (text)
==============================
I'm wondering what's the difficulty you encounter here. To display the
results, I think it include two parts:

** first, you need to execute the SQSL stored procedure and get the
returned resultset(need to supply the parameter)

**second, you should bind the resultset to the gridview control

for calling stored procedure in ASP.NET, here are many reference:

#How to call SQL Server stored procedures in ASP.NET by using Visual
Basic
.NET
http://support.microsoft.com/kb/306574

And you can also use SQL Datasource control in ASP.NET 2.0 which make
databinding/query more convenient:

#SQLDataSource Control
http://www.learn-asp.net/ASPTutorial...ceControl.aspx

http://www.asp.net/LEARN/data-access...ial-47-cs.aspx
For bind resultset to Gridview, I think it's quite straightforward:

** if you query the database programmtically, you need to assign the
result
>>>set(datatable or datareader) to Gridview and call DataBind method. e.g.

Gridview1.DataSource = [returned data resultset];
Gridview1.DataBind();

Or you can use SqlDataSource control(refer to the aritlce I mentioned
above).

2) Adds an extra column that displays the result of a VB.Net function
that
uses a value from an existing column
================================
I think the natural approach is adding a template column which use other
existing column's datafield to compute the certain value you want. Here
are
>>>some reference about using template column:

#Using TemplateFields in the GridView Control
http://www.asp.net/learn/data-access...ial-12-cs.aspx

#GridView Examples for ASP.NET 2.0: Working with TemplateFields
http://msdn.microsoft.com/en-us/library/aa479353.aspx
And here is a simple example. I use a gridview to display data through a
SqlDataSource control and it contains two columns by default. I add an
additional template column which use a helper function(to calculate the
display value depend on the two existing column value):

>>>>>>>>>aspx template>>>>>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$
ConnectionStrings:testdbConnectionString
%>"
SelectCommand="SELECT [id], [name] FROM
[numtable]"></asp:SqlDataSource>
<br />
<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False"
DataKeyNames="id" DataSourceID="SqlDataSource1">
<Columns>
<asp:BoundField DataField="id" HeaderText="id"
ReadOnly="True"
SortExpression="id" />
<asp:BoundField DataField="name" HeaderText="name"
SortExpression="name" />
<asp:TemplateField>
<ItemTemplate>
<%# MyFunction(Eval("id"), Eval("name")) %>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

>>>>>>>code behind>>>>>>>>>>>>>>>
protected string MyFunction(object id, object name)
{
return id.ToString() + "|" + name.ToString();
}

>>>>>>>>>>>>>>>>>>>>>

In addition, if you do not have much ASP.NET programming experience, I
would suggest you have a look at the tutorials on ASP.NET offical site:

http://www.asp.net/learn/

and since you're developing data access application, the "Data Access
tutorial" is especially important for you:

http://www.asp.net/learn/data-access/

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you.
Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

=============================================== ===
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ault.aspx#noti
f
>>>ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent
issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each
follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
=============================================== ===
This posting is provided "AS IS" with no warranties, and confers no
rights.

--------------------
From: "Mark B" <no**@none.com>
Subject: Datagrid example
Date: Fri, 30 May 2008 13:10:32 +1200
Can someone write some VB.Net example code for me that does this:

1) Creates a gridview control with the results of a SQL stored procedure
that has 1 parameter (text)

2) Adds an extra column that displays the result of a VB.Net function
that
>>>>uses a value from an existing column

I have spent 4 hours trying to do this after Googling for examples...
There
are many new concepts that I haven't had much experience with...

Jun 27 '08 #5

P: n/a
thanks for your reply Mark,

From the aspx template snippet you provided, you 've configured the
DataGrid control to connect a SqlDataSource(which supply the data resultset
to DataGrid). Also, you've applied a certain style format and most of the
mark attribute it is for style format(such as color and font). You can
first remove the format/style so as to make the markup looks more clear.

As for the question you mentioned below:
===============
So my question is, if if follow the example below and type in VB.Net code,
will this conflict with what I already have with the HTML? Which one will
take precedence?
==============

Would you let me know the code you added? Are you adding additional
databinding code? Generally for ASP.NET 2.0, if you have already supplied
an SqlDatasource control(and correctly configure the Datasource control
properties) and attached it to the databound control(like DataGrid,
Gridview), the the databound control should be able to populate data
correctly without additional code.

Sincerely,

Steven Cheng
Microsoft MSDN Online Support Lead

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
>From: "Mark B" <no**@none.com>
References: <u8**************@TK2MSFTNGP02.phx.gbl>
<gA**************@TK2MSFTNGHUB02.phx.gbl>
<Hf**************@TK2MSFTNGHUB02.phx.gbl>
<uB*************@TK2MSFTNGP05.phx.gbl>
>In-Reply-To: <uB*************@TK2MSFTNGP05.phx.gbl>
Subject: Re: Datagrid example
Date: Wed, 4 Jun 2008 16:26:46 +1200
>
When I drag the Datagrid control over to the design view of an aspx page,
it
>prompts me for many things like datasource, fields etc. After I fill all
of
>these in I notice it creates quite a lot of html:

e.g.

<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:MyDBConnectionString %>"
SelectCommand="uspGroupsDataGridSource"
SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:QueryStringParameter DefaultValue="Group1"
Name="EnterMasterGroupName"
QueryStringField="SelectedGroup" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AllowSorting="True" AutoGenerateColumns="False" CellPadding="4"
DataSourceID="SqlDataSource1" ForeColor="#333333" GridLines="None">
<FooterStyle BackColor="#5D7B9D" Font-Bold="True"
ForeColor="White"
>/>
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<Columns>
<asp:BoundField DataField="GroupName" HeaderText="GroupName"
SortExpression="GroupName" />
<asp:BoundField DataField="AverageSales30Days"
HeaderText="AverageSales30Days"
ReadOnly="True" SortExpression="AverageSales30Days" />
<asp:BoundField DataField="AverageGrade30Days"
HeaderText="AverageGrade30Days"
ReadOnly="True" SortExpression="AverageGrade30Days" />
<asp:BoundField DataField="AverageSales6Months"
HeaderText="AverageSales6Months"
ReadOnly="True" SortExpression="AverageSales6Months" />
<asp:BoundField DataField="AverageGrade6Months"
HeaderText="AverageGrade6Months" ReadOnly="True"
SortExpression="AverageGrade6Months" />
<asp:BoundField DataField="AverageSales12Months"
HeaderText="AverageSales12Months"
ReadOnly="True" SortExpression="AverageSales12Months" />
<asp:BoundField DataField="AverageGrade12Months"
HeaderText="AverageGrade12Months" ReadOnly="True"
SortExpression="AverageGrade12Months" />
</Columns>
<PagerStyle BackColor="#284775" ForeColor="White"
HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True"
ForeColor="#333333" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True"
ForeColor="White"
>/>
<EditRowStyle BackColor="#999999" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
</asp:GridView>


So my question is, if if follow the example below and type in VB.Net code,
will this conflict with what I already have with the HTML? Which one will
take precedence?

Do I need to delete some of the HTML?

Jun 27 '08 #6

P: n/a
It turns out so far I have been able to do it all using the markup as you
showed so at present there is no need to use additional VB.net on it. Thanks
for your help.

"Steven Cheng [MSFT]" <st*****@online.microsoft.comwrote in message
news:IC**************@TK2MSFTNGHUB02.phx.gbl...
thanks for your reply Mark,

From the aspx template snippet you provided, you 've configured the
DataGrid control to connect a SqlDataSource(which supply the data
resultset
to DataGrid). Also, you've applied a certain style format and most of the
mark attribute it is for style format(such as color and font). You can
first remove the format/style so as to make the markup looks more clear.

As for the question you mentioned below:
===============
So my question is, if if follow the example below and type in VB.Net code,
will this conflict with what I already have with the HTML? Which one will
take precedence?
==============

Would you let me know the code you added? Are you adding additional
databinding code? Generally for ASP.NET 2.0, if you have already supplied
an SqlDatasource control(and correctly configure the Datasource control
properties) and attached it to the databound control(like DataGrid,
Gridview), the the databound control should be able to populate data
correctly without additional code.

Sincerely,

Steven Cheng
Microsoft MSDN Online Support Lead

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.
==================================================
This posting is provided "AS IS" with no warranties, and confers no
rights.

--------------------
>>From: "Mark B" <no**@none.com>
References: <u8**************@TK2MSFTNGP02.phx.gbl>
<gA**************@TK2MSFTNGHUB02.phx.gbl>
<Hf**************@TK2MSFTNGHUB02.phx.gbl>
<uB*************@TK2MSFTNGP05.phx.gbl>
>>In-Reply-To: <uB*************@TK2MSFTNGP05.phx.gbl>
Subject: Re: Datagrid example
Date: Wed, 4 Jun 2008 16:26:46 +1200
>>
When I drag the Datagrid control over to the design view of an aspx page,
it
>>prompts me for many things like datasource, fields etc. After I fill all
of
>>these in I notice it creates quite a lot of html:

e.g.

<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:MyDBConnectionString %>"
SelectCommand="uspGroupsDataGridSource"
SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:QueryStringParameter DefaultValue="Group1"
Name="EnterMasterGroupName"
QueryStringField="SelectedGroup" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AllowSorting="True" AutoGenerateColumns="False" CellPadding="4"
DataSourceID="SqlDataSource1" ForeColor="#333333"
GridLines="None">
<FooterStyle BackColor="#5D7B9D" Font-Bold="True"
ForeColor="White"
>>/>
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<Columns>
<asp:BoundField DataField="GroupName" HeaderText="GroupName"
SortExpression="GroupName" />
<asp:BoundField DataField="AverageSales30Days"
HeaderText="AverageSales30Days"
ReadOnly="True" SortExpression="AverageSales30Days" />
<asp:BoundField DataField="AverageGrade30Days"
HeaderText="AverageGrade30Days"
ReadOnly="True" SortExpression="AverageGrade30Days" />
<asp:BoundField DataField="AverageSales6Months"
HeaderText="AverageSales6Months"
ReadOnly="True" SortExpression="AverageSales6Months" />
<asp:BoundField DataField="AverageGrade6Months"
HeaderText="AverageGrade6Months" ReadOnly="True"
SortExpression="AverageGrade6Months" />
<asp:BoundField DataField="AverageSales12Months"
HeaderText="AverageSales12Months"
ReadOnly="True" SortExpression="AverageSales12Months" />
<asp:BoundField DataField="AverageGrade12Months"
HeaderText="AverageGrade12Months" ReadOnly="True"
SortExpression="AverageGrade12Months" />
</Columns>
<PagerStyle BackColor="#284775" ForeColor="White"
HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True"
ForeColor="#333333" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True"
ForeColor="White"
>>/>
<EditRowStyle BackColor="#999999" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
</asp:GridView>


So my question is, if if follow the example below and type in VB.Net code,
will this conflict with what I already have with the HTML? Which one will
take precedence?

Do I need to delete some of the HTML?

Jun 27 '08 #7

P: n/a
Thanks for your reply Mark,

Yes, ASP.NET 2.0 databinding model makes some simple and common data access
scenarios very convenient to achieve. If you need any further help, welcome
to post here.

Sincerely,

Steven Cheng
Microsoft MSDN Online Support Lead
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
>From: "Mark B" <no**@none.com>
In-Reply-To: <IC**************@TK2MSFTNGHUB02.phx.gbl>
Subject: Re: Datagrid example
Date: Thu, 5 Jun 2008 22:03:25 +1200
>It turns out so far I have been able to do it all using the markup as you
showed so at present there is no need to use additional VB.net on it.
Thanks
>for your help.

"
Jun 27 '08 #8

This discussion thread is closed

Replies have been disabled for this discussion.