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/ASPTutorials/SQLDataSourceControl.aspx
http://www.asp.net/LEARN/data-access/tutorial-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/tutorial-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:
(e-mail address removed).
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.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/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no
rights.
--------------------
From: "Mark B" <
[email protected]>
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...