0

This is homework assignment that isn't covered in our books and we were instructed to use the internet and/or any other resources to figure out this assignment. The information I'm finding on the web is a little over my head and was hoping for a more laymen explanation!!

I have an existing asp.net web site using c#, without issue I was able to add dynamic data capabilities to my site by creating a dummy site, hooked up to AdventureWorks DB, and adding the appropriate files and assemblies to my existing site.

This is where I am getting lost. I need to use one of the stored procedures in the Adventure Works DB to display data on a page. I am attempting to use the uspGetEmployeeManagers by associating it with a listview on my aspx page. This is pretty much as far as I can get. All the blogs I've read are a little over my head and I've become more confused than when I started.

Can someone please explain to me, as simply as possible, what I need to do to display data using a stored procedure in a dynamic data web site?

Thank you!

Code:

    protected void getEmployeeManagers(int employeeID)
{
    AdventureWorksLTDataContext aventureWorksDataContext = new AdventureWorksLTDataContext();

    var dynamicData = aventureWorksDataContext.uspGetEmployeeManagers(employeeID);

    lvwGetEmployeeManager.DataSource = dynamicData;
    lvwGetEmployeeManager.DataBind();
}
Ehsan Sajjad
  • 61,834
  • 16
  • 105
  • 160

1 Answers1

0

You can use any data source you want for the most part. You need to hook up the data to the listview correctly. Here an example:

Markup

    <div id= "Test1a" class="fieldgroup" runat="server">
    <asp:Panel ID="panelWithHistoryControl" runat="server">            
        <asp:ListView ID="test1" runat="server" OnLoad="test1_OnLoad">
            <LayoutTemplate>
                <asp:PlaceHolder runat="server" ID="test1PlaceHolder"></asp:PlaceHolder>
            </LayoutTemplate>
            <ItemTemplate>
                <table>
                        <tr>
                            <td><%# Eval("Column1")%></td>
                            <td><%# Eval("Column2")%></td>
                        </tr>
                    </table>
            </ItemTemplate>
        </asp:ListView>           
    </asp:Panel></div>

Column1 and Column2 are the table columns or interface property names etc.

Code Behind

public void test1_OnLoad(object sender, EventArgs e)
{     
    var list = // Get your data from the database.  Return as an IList<T> or something   
               //similar.

    test1.DataSource = list;
    test1.ItemPlaceholderID = "test1PlaceHolder";
    test1.DataBind();
}

References http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listview.itemtemplate.aspx

https://web.archive.org/web/20211020153238/https://www.4guysfromrolla.com/articles/122607-1.aspx

Finally, executing stored procedures from C# is fairly straight forward. There are many sources See: How to execute a stored procedure within C# program

http://msdn.microsoft.com/en-us/library/bb399407(v=vs.110).aspx

http://msdn.microsoft.com/en-us/library/d7125bke.aspx

Community
  • 1
  • 1
tdbeckett
  • 618
  • 8
  • 19