Datagrid example

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mark B

    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...

  • Steven Cheng [MSFT]

    #2
    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


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

    #SQLDataSource Control


    Build web apps and services that run on Windows, Linux, and macOS using C#, HTML, CSS, and JavaScript. Get started for free on Windows, Linux, or macOS.



    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.DataS ource = [returned data resultset];
    Gridview1.DataB ind();

    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
    Build web apps and services that run on Windows, Linux, and macOS using C#, HTML, CSS, and JavaScript. Get started for free on Windows, Linux, or macOS.


    #GridView Examples for ASP.NET 2.0: Working with TemplateFields



    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):
    >>>>>>>>>>asp x template>>>>>
    <asp:SqlDataSou rce ID="SqlDataSour ce1" runat="server"
    ConnectionStrin g="<%$ ConnectionStrin gs:testdbConnec tionString
    %>"
    SelectCommand=" SELECT [id], [name] FROM
    [numtable]"></asp:SqlDataSour ce>
    <br />
    <asp:GridView ID="GridView1" runat="server"
    AutoGenerateCol umns="False"
    DataKeyNames="i d" DataSourceID="S qlDataSource1">
    <Columns>
    <asp:BoundFie ld DataField="id" HeaderText="id"
    ReadOnly="True"
    SortExpression= "id" />
    <asp:BoundFie ld DataField="name " HeaderText="nam e"
    SortExpression= "name" />
    <asp:TemplateFi eld>
    <ItemTemplate >
    <%# MyFunction(Eval ("id"), Eval("name")) %>
    </ItemTemplate>
    </asp:TemplateFie ld>
    </Columns>
    </asp:GridView>
    >>>>>>>>code behind>>>>>>>>> >>>>>>
    protected string MyFunction(obje ct 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:

    Build web apps and services that run on Windows, Linux, and macOS using C#, HTML, CSS, and JavaScript. Get started for free on Windows, Linux, or macOS.


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

    Build web apps and services that run on Windows, Linux, and macOS using C#, HTML, CSS, and JavaScript. Get started for free on Windows, Linux, or macOS.


    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:
    msdnmg@microsof t.com.

    =============== =============== =============== =====
    Get notification to my posts through email? Please refer to
    Find official documentation, practical know-how, and expert guidance for builders working and troubleshooting in Microsoft products.

    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" <none@none.co m>
    >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...
    >
    >

    Comment

    • Steven Cheng [MSFT]

      #3
      RE: Datagrid example

      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:
      msdnmg@microsof t.com.

      =============== =============== =============== =====
      Get notification to my posts through email? Please refer to
      Find official documentation, practical know-how, and expert guidance for builders working and troubleshooting in Microsoft products.

      ications.



      --------------------
      >From: stcheng@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:
      >
      >#SQLDataSour ce 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(datatabl e or datareader) to Gridview and call DataBind method. e.g.
      >
      >Gridview1.Data Source = [returned data resultset];
      >Gridview1.Data Bind();
      >
      >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
      >SqlDataSourc e 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):
      >
      >>>>>>>>>>>as px template>>>>>
      <asp:SqlDataSou rce ID="SqlDataSour ce1" runat="server"
      ConnectionStrin g="<%$ ConnectionStrin gs:testdbConnec tionString
      >%>"
      SelectCommand=" SELECT [id], [name] FROM
      >[numtable]"></asp:SqlDataSour ce>
      <br />
      <asp:GridView ID="GridView1" runat="server"
      >AutoGenerateCo lumns="False"
      DataKeyNames="i d" DataSourceID="S qlDataSource1">
      <Columns>
      <asp:BoundFie ld DataField="id" HeaderText="id"
      >ReadOnly="True "
      SortExpression= "id" />
      <asp:BoundFie ld DataField="name " HeaderText="nam e"
      >SortExpression ="name" />
      <asp:TemplateFi eld>
      <ItemTemplate >
      <%# MyFunction(Eval ("id"), Eval("name")) %>
      </ItemTemplate>
      </asp:TemplateFie ld>
      </Columns>
      </asp:GridView>
      >
      >>>>>>>>>code behind>>>>>>>>> >>>>>>
      >protected string MyFunction(obje ct 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:
      >msdnmg@microso ft.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" <none@none.co m>
      >>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...
      >>
      >>
      >
      >

      Comment

      • Mark B

        #4
        Re: Datagrid example

        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]" <stcheng@online .microsoft.comw rote in message
        news:Hfo15XUxIH A.1784@TK2MSFTN GHUB02.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:
        msdnmg@microsof t.com.
        >
        =============== =============== =============== =====
        Get notification to my posts through email? Please refer to
        Find official documentation, practical know-how, and expert guidance for builders working and troubleshooting in Microsoft products.

        ications.
        >
        >
        >
        --------------------
        >>From: stcheng@online. microsoft.com (Steven Cheng [MSFT])
        >>Organizatio n: 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:
        >>
        >>#SQLDataSourc e 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(datatab le or datareader) to Gridview and call DataBind method. e.g.
        >>
        >>Gridview1.Dat aSource = [returned data resultset];
        >>Gridview1.Dat aBind();
        >>
        >>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
        >>SqlDataSour ce 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):
        >>
        >>>>>>>>>>>>asp x template>>>>>
        ><asp:SqlDataSo urce ID="SqlDataSour ce1" runat="server"
        > ConnectionStrin g="<%$ ConnectionStrin gs:testdbConnec tionString
        >>%>"
        > SelectCommand=" SELECT [id], [name] FROM
        >>[numtable]"></asp:SqlDataSour ce>
        > <br />
        > <asp:GridView ID="GridView1" runat="server"
        >>AutoGenerateC olumns="False"
        > DataKeyNames="i d" DataSourceID="S qlDataSource1">
        > <Columns>
        > <asp:BoundFie ld DataField="id" HeaderText="id"
        >>ReadOnly="Tru e"
        > SortExpression= "id" />
        > <asp:BoundFie ld DataField="name " HeaderText="nam e"
        >>SortExpressio n="name" />
        > <asp:TemplateFi eld>
        > <ItemTemplate >
        > <%# MyFunction(Eval ("id"), Eval("name")) %>
        > </ItemTemplate>
        > </asp:TemplateFie ld>
        > </Columns>
        > </asp:GridView>
        >>
        >>>>>>>>>>cod e behind>>>>>>>>> >>>>>>
        >>protected string MyFunction(obje ct 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:
        >>msdnmg@micros oft.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
        >>professiona l 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" <none@none.co m>
        >>>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...
        >>>
        >>>
        >>
        >>
        >

        Comment

        • Mark B

          #5
          Re: Datagrid example

          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:SqlDataSou rce ID="SqlDataSour ce1" runat="server"
          ConnectionStrin g="<%$ ConnectionStrin gs:MyDBConnecti onString %>"
          SelectCommand=" uspGroupsDataGr idSource"
          SelectCommandTy pe="StoredProce dure">
          <SelectParamete rs>
          <asp:QueryStrin gParameter DefaultValue="G roup1"
          Name="EnterMast erGroupName"
          QueryStringFiel d="SelectedGrou p" Type="String" />
          </SelectParameter s>
          </asp:SqlDataSour ce>
          <asp:GridView ID="GridView1" runat="server" AllowPaging="Tr ue"
          AllowSorting="T rue" AutoGenerateCol umns="False" CellPadding="4"
          DataSourceID="S qlDataSource1" ForeColor="#333 333" GridLines="None ">
          <FooterStyle BackColor="#5D7 B9D" Font-Bold="True" ForeColor="Whit e"
          />
          <RowStyle BackColor="#F7F 6F3" ForeColor="#333 333" />
          <Columns>
          <asp:BoundFie ld DataField="Grou pName" HeaderText="Gro upName"
          SortExpression= "GroupName" />
          <asp:BoundFie ld DataField="Aver ageSales30Days"
          HeaderText="Ave rageSales30Days "
          ReadOnly="True" SortExpression= "AverageSales30 Days" />
          <asp:BoundFie ld DataField="Aver ageGrade30Days"
          HeaderText="Ave rageGrade30Days "
          ReadOnly="True" SortExpression= "AverageGrade30 Days" />
          <asp:BoundFie ld DataField="Aver ageSales6Months "
          HeaderText="Ave rageSales6Month s"
          ReadOnly="True" SortExpression= "AverageSales6M onths" />
          <asp:BoundFie ld DataField="Aver ageGrade6Months "
          HeaderText="Ave rageGrade6Month s" ReadOnly="True"
          SortExpression= "AverageGrade6M onths" />
          <asp:BoundFie ld DataField="Aver ageSales12Month s"
          HeaderText="Ave rageSales12Mont hs"
          ReadOnly="True" SortExpression= "AverageSales12 Months" />
          <asp:BoundFie ld DataField="Aver ageGrade12Month s"
          HeaderText="Ave rageGrade12Mont hs" ReadOnly="True"
          SortExpression= "AverageGrade12 Months" />
          </Columns>
          <PagerStyle BackColor="#284 775" ForeColor="Whit e"
          HorizontalAlign ="Center" />
          <SelectedRowSty le BackColor="#E2D ED6" Font-Bold="True"
          ForeColor="#333 333" />
          <HeaderStyle BackColor="#5D7 B9D" Font-Bold="True" ForeColor="Whit e"
          />
          <EditRowStyle BackColor="#999 999" />
          <AlternatingRow Style BackColor="Whit e" ForeColor="#284 775" />
          </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" <none@none.comw rote in message
          news:uBxmBkfxIH A.704@TK2MSFTNG P05.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]" <stcheng@online .microsoft.comw rote in message
          news:Hfo15XUxIH A.1784@TK2MSFTN GHUB02.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:
          >msdnmg@microsof t.com.
          >>
          >============== =============== =============== ======
          >Get notification to my posts through email? Please refer to
          >http://msdn.microsoft.com/subscripti...ult.aspx#notif
          >ications.
          >>
          >>
          >>
          >--------------------
          >>>From: stcheng@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
          >>>databindin g/query more convenient:
          >>>
          >>>#SQLDataSour ce 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(datatabl e or datareader) to Gridview and call DataBind method. e.g.
          >>>
          >>>Gridview1.Da taSource = [returned data resultset];
          >>>Gridview1.Da taBind();
          >>>
          >>>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
          >>>SqlDataSourc e 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):
          >>>
          >>>>>>>>>>>>>as px template>>>>>
          >><asp:SqlDataS ource ID="SqlDataSour ce1" runat="server"
          >> ConnectionStrin g="<%$
          >>ConnectionStr ings:testdbConn ectionString
          >>>%>"
          >> SelectCommand=" SELECT [id], [name] FROM
          >>>[numtable]"></asp:SqlDataSour ce>
          >> <br />
          >> <asp:GridView ID="GridView1" runat="server"
          >>>AutoGenerate Columns="False"
          >> DataKeyNames="i d" DataSourceID="S qlDataSource1">
          >> <Columns>
          >> <asp:BoundFie ld DataField="id" HeaderText="id"
          >>>ReadOnly="Tr ue"
          >> SortExpression= "id" />
          >> <asp:BoundFie ld DataField="name " HeaderText="nam e"
          >>>SortExpressi on="name" />
          >> <asp:TemplateFi eld>
          >> <ItemTemplate >
          >> <%# MyFunction(Eval ("id"), Eval("name")) %>
          >> </ItemTemplate>
          >> </asp:TemplateFie ld>
          >> </Columns>
          >> </asp:GridView>
          >>>
          >>>>>>>>>>>co de behind>>>>>>>>> >>>>>>
          >>>protected string MyFunction(obje ct 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
          >>>suggestion s 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:
          >>>msdnmg@micro soft.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
          >>>profession al 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" <none@none.co m>
          >>>>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...
          >>>>
          >>>>
          >>>
          >>>
          >>
          >

          Comment

          • Steven Cheng [MSFT]

            #6
            Re: Datagrid example

            thanks for your reply Mark,

            From the aspx template snippet you provided, you 've configured the
            DataGrid control to connect a SqlDataSource(w hich 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:
            msdnmg@microsof t.com.

            =============== =============== =============== =====
            Get notification to my posts through email? Please refer to
            Find official documentation, practical know-how, and expert guidance for builders working and troubleshooting in Microsoft products.

            ications.
            =============== =============== =============== =====
            This posting is provided "AS IS" with no warranties, and confers no rights.

            --------------------
            >From: "Mark B" <none@none.co m>
            >References: <u8757HfwIHA.50 96@TK2MSFTNGP02 .phx.gbl>
            <gARxXigwIHA.57 96@TK2MSFTNGHUB 02.phx.gbl>
            <Hfo15XUxIHA.17 84@TK2MSFTNGHUB 02.phx.gbl>
            <uBxmBkfxIHA.70 4@TK2MSFTNGP05. phx.gbl>
            >In-Reply-To: <uBxmBkfxIHA.70 4@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:SqlDataSo urce ID="SqlDataSour ce1" runat="server"
            ConnectionStrin g="<%$ ConnectionStrin gs:MyDBConnecti onString %>"
            SelectCommand=" uspGroupsDataGr idSource"
            SelectCommandTy pe="StoredProce dure">
            <SelectParamete rs>
            <asp:QueryStrin gParameter DefaultValue="G roup1"
            >Name="EnterMas terGroupName"
            QueryStringFiel d="SelectedGrou p" Type="String" />
            </SelectParameter s>
            </asp:SqlDataSour ce>
            <asp:GridView ID="GridView1" runat="server" AllowPaging="Tr ue"
            AllowSorting="T rue" AutoGenerateCol umns="False" CellPadding="4"
            DataSourceID="S qlDataSource1" ForeColor="#333 333" GridLines="None ">
            <FooterStyle BackColor="#5D7 B9D" Font-Bold="True"
            ForeColor="Whit e"
            >/>
            <RowStyle BackColor="#F7F 6F3" ForeColor="#333 333" />
            <Columns>
            <asp:BoundFie ld DataField="Grou pName" HeaderText="Gro upName"
            SortExpression= "GroupName" />
            <asp:BoundFie ld DataField="Aver ageSales30Days"
            >HeaderText="Av erageSales30Day s"
            ReadOnly="True" SortExpression= "AverageSales30 Days" />
            <asp:BoundFie ld DataField="Aver ageGrade30Days"
            >HeaderText="Av erageGrade30Day s"
            ReadOnly="True" SortExpression= "AverageGrade30 Days" />
            <asp:BoundFie ld DataField="Aver ageSales6Months "
            >HeaderText="Av erageSales6Mont hs"
            ReadOnly="True" SortExpression= "AverageSales6M onths" />
            <asp:BoundFie ld DataField="Aver ageGrade6Months "
            HeaderText="Ave rageGrade6Month s" ReadOnly="True"
            SortExpression= "AverageGrade6M onths" />
            <asp:BoundFie ld DataField="Aver ageSales12Month s"
            >HeaderText="Av erageSales12Mon ths"
            ReadOnly="True" SortExpression= "AverageSales12 Months" />
            <asp:BoundFie ld DataField="Aver ageGrade12Month s"
            HeaderText="Ave rageGrade12Mont hs" ReadOnly="True"
            SortExpression= "AverageGrade12 Months" />
            </Columns>
            <PagerStyle BackColor="#284 775" ForeColor="Whit e"
            >HorizontalAlig n="Center" />
            <SelectedRowSty le BackColor="#E2D ED6" Font-Bold="True"
            >ForeColor="#33 3333" />
            <HeaderStyle BackColor="#5D7 B9D" Font-Bold="True"
            ForeColor="Whit e"
            >/>
            <EditRowStyle BackColor="#999 999" />
            <AlternatingRow Style BackColor="Whit e" ForeColor="#284 775" />
            </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?
            >
            >
            >
            >

            Comment

            • Mark B

              #7
              Re: Datagrid example

              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]" <stcheng@online .microsoft.comw rote in message
              news:ICqSwatxIH A.4564@TK2MSFTN GHUB02.phx.gbl. ..
              thanks for your reply Mark,
              >
              From the aspx template snippet you provided, you 've configured the
              DataGrid control to connect a SqlDataSource(w hich 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:
              msdnmg@microsof t.com.
              >
              =============== =============== =============== =====
              Get notification to my posts through email? Please refer to
              Find official documentation, practical know-how, and expert guidance for builders working and troubleshooting in Microsoft products.

              ications.
              =============== =============== =============== =====
              This posting is provided "AS IS" with no warranties, and confers no
              rights.
              >
              --------------------
              >>From: "Mark B" <none@none.co m>
              >>References: <u8757HfwIHA.50 96@TK2MSFTNGP02 .phx.gbl>
              <gARxXigwIHA.57 96@TK2MSFTNGHUB 02.phx.gbl>
              <Hfo15XUxIHA.17 84@TK2MSFTNGHUB 02.phx.gbl>
              <uBxmBkfxIHA.70 4@TK2MSFTNGP05. phx.gbl>
              >>In-Reply-To: <uBxmBkfxIHA.70 4@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:SqlDataS ource ID="SqlDataSour ce1" runat="server"
              > ConnectionStrin g="<%$ ConnectionStrin gs:MyDBConnecti onString %>"
              > SelectCommand=" uspGroupsDataGr idSource"
              > SelectCommandTy pe="StoredProce dure">
              > <SelectParamete rs>
              > <asp:QueryStrin gParameter DefaultValue="G roup1"
              >>Name="EnterMa sterGroupName"
              > QueryStringFiel d="SelectedGrou p" Type="String" />
              > </SelectParameter s>
              > </asp:SqlDataSour ce>
              > <asp:GridView ID="GridView1" runat="server" AllowPaging="Tr ue"
              > AllowSorting="T rue" AutoGenerateCol umns="False" CellPadding="4"
              > DataSourceID="S qlDataSource1" ForeColor="#333 333"
              >GridLines="Non e">
              > <FooterStyle BackColor="#5D7 B9D" Font-Bold="True"
              ForeColor="Whit e"
              >>/>
              > <RowStyle BackColor="#F7F 6F3" ForeColor="#333 333" />
              > <Columns>
              > <asp:BoundFie ld DataField="Grou pName" HeaderText="Gro upName"
              > SortExpression= "GroupName" />
              > <asp:BoundFie ld DataField="Aver ageSales30Days"
              >>HeaderText="A verageSales30Da ys"
              > ReadOnly="True" SortExpression= "AverageSales30 Days" />
              > <asp:BoundFie ld DataField="Aver ageGrade30Days"
              >>HeaderText="A verageGrade30Da ys"
              > ReadOnly="True" SortExpression= "AverageGrade30 Days" />
              > <asp:BoundFie ld DataField="Aver ageSales6Months "
              >>HeaderText="A verageSales6Mon ths"
              > ReadOnly="True" SortExpression= "AverageSales6M onths" />
              > <asp:BoundFie ld DataField="Aver ageGrade6Months "
              > HeaderText="Ave rageGrade6Month s" ReadOnly="True"
              > SortExpression= "AverageGrade6M onths" />
              > <asp:BoundFie ld DataField="Aver ageSales12Month s"
              >>HeaderText="A verageSales12Mo nths"
              > ReadOnly="True" SortExpression= "AverageSales12 Months" />
              > <asp:BoundFie ld DataField="Aver ageGrade12Month s"
              > HeaderText="Ave rageGrade12Mont hs" ReadOnly="True"
              > SortExpression= "AverageGrade12 Months" />
              > </Columns>
              > <PagerStyle BackColor="#284 775" ForeColor="Whit e"
              >>HorizontalAli gn="Center" />
              > <SelectedRowSty le BackColor="#E2D ED6" Font-Bold="True"
              >>ForeColor="#3 33333" />
              > <HeaderStyle BackColor="#5D7 B9D" Font-Bold="True"
              ForeColor="Whit e"
              >>/>
              > <EditRowStyle BackColor="#999 999" />
              > <AlternatingRow Style BackColor="Whit e" ForeColor="#284 775" />
              > </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?
              >>
              >>
              >>
              >>
              >

              Comment

              • Steven Cheng [MSFT]

                #8
                Re: Datagrid example

                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:
                msdnmg@microsof t.com.

                =============== =============== =============== =====
                Get notification to my posts through email? Please refer to
                Find official documentation, practical know-how, and expert guidance for builders working and troubleshooting in Microsoft products.

                ications.

                =============== =============== =============== =====
                This posting is provided "AS IS" with no warranties, and confers no rights.
                --------------------
                >From: "Mark B" <none@none.co m>
                >In-Reply-To: <ICqSwatxIHA.45 64@TK2MSFTNGHUB 02.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.
                >
                >"

                Comment

                Working...