473,396 Members | 2,011 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Datagrid example

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
7 3006
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Vagabond Software | last post by:
I am creating a custom datagrid based, in part, from someone else's code. The author declared a derived datagrid class in a windows form, then declared a derived ColumnStyle class, in the same form,...
0
by: Mauro | last post by:
Hi, I need a big help to resolve this problem. I need to put a usercontrol in a datagrid: this control check if the code inserted is present in a archive and if not return a error message. (In...
3
by: Richard | last post by:
I have a requirement to put a GDI style circle or rectangle border around the selected row of a datagrid/ It will overlap into the row above and below the selected row. Doing this in a the OnPaint...
3
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that...
1
by: sianan | last post by:
I tried to use the following example, to add a checkbox column to a DataGrid in an ASP.NET application: http://www.codeproject.com/aspnet/datagridcheckbox.asp For some reason, I simply CAN'T get...
4
by: jaYPee | last post by:
I have 1 dataset called "dataset1" that contains 2 tables called "course" and "courseload". in my form i have a datagrid. the datasource of this datagrid is "dataset1" and the datamember is...
7
by: BobAchgill | last post by:
I am trying to decide which of these controls to use to implement letting my user select a full row from MyList. The MyList has several columns which would be nice to sort by at run time. The...
3
by: chreo | last post by:
Hello. I have datagrid. I found code to select all row in data grid (by mouse or arrow keys). This works great - user can select row and... ....and I want to go to next control. For...
15
by: glenn | last post by:
Hi folks, I have a DropDownList in a DataGrid that is populated from records in a database. I want to add a value that might be a string such as "Select a Company" for the first item since an...
0
by: TonyJ | last post by:
Hello! I'm unsure when I can use a bound datagrid and when I can't. What limitations has a bound datagrid? 1. For example if I want to manipulate the data in the datasource before displaying...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.