Inserting a row at runtime

  • (2 Pages)
  • +
  • 1
  • 2

20 Replies - 7181 Views - Last Post: 27 October 2010 - 04:24 PM Rate Topic: -----

#1 samuel17   User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 209
  • Joined: 14-October 10

Inserting a row at runtime

Posted 16 October 2010 - 03:18 PM

Hi all,
I just started trying to make some webpages using using Visual Web Developer and i have a table that is linked to a list box so that if something is clicked in the list box that it changed in the grid below. Not sure if that is relavent, but any way, what i am trying to do is at runtime have there be a button that you can click and have it add a new row at the bottom of the table and you can add new data into the table. I know there is a way, like an Insert Function but im not sure how to do it. Thanks in advance to anyone who can help me.

Sam

Is This A Good Question/Topic? 0
  • +

Replies To: Inserting a row at runtime

#2 Skaggles   User is offline

  • THE PEN IS MIGHTIER
  • member icon





Reputation: 255
  • View blog
  • Posts: 641
  • Joined: 01-March 09

Re: Inserting a row at runtime

Posted 16 October 2010 - 05:30 PM

Perhaps you are thinking of using Javascript, which would let you insert HTML into the page without refreshing. It could accomplish the affect you desire of adding in a form for data input upon a button click.

This might be helpful: Replace the text in HTML elements
Was This Post Helpful? 0
  • +
  • -

#3 Nakor   User is offline

  • Professional Lurker
  • member icon

Reputation: 448
  • View blog
  • Posts: 1,504
  • Joined: 28-April 09

Re: Inserting a row at runtime

Posted 16 October 2010 - 09:59 PM

It depends on the control you are using to display the Grid. If you are using a GridView then it does not natively support insertion of new rows. A FormView or DetailsView would possibly work since they both support insertion. If you're set on using a GridView then there is a post here that describes a way to do it.
Was This Post Helpful? 0
  • +
  • -

#4 samuel17   User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 209
  • Joined: 14-October 10

Re: Inserting a row at runtime

Posted 17 October 2010 - 08:28 AM

I do prefer the look of the gridview, and also when i click on the item in my listbox the gridview shows all the items together on one grid compared to the formview and design view where you have to enable paging to see the rest of the records that apply to the parameter. I also like that the gridview has the column headers on top compared to having them on the left side in the other 2. Is there a way that i can set the other 2 up so that they look more like the gridview does? I much prefer an easy setup compared to doing all the coding just for that like the link shows, i kept getting syntax errors when i tried entering the code as the link showed. Also im coding this in Visual Basic if that helps.

Thanks a lot,
Sam
Was This Post Helpful? 0
  • +
  • -

#5 Nakor   User is offline

  • Professional Lurker
  • member icon

Reputation: 448
  • View blog
  • Posts: 1,504
  • Joined: 28-April 09

Re: Inserting a row at runtime

Posted 17 October 2010 - 11:29 AM

Well, another option is to use a ListView. They can sometimes require a little more effort but in my opinion are more flexible. They can be used to produce a nice grid layout that supports updating, editing, deleting and inserting.

More resources on ListView:
ListView Control
Modifying Data With the ListView Control
Was This Post Helpful? 0
  • +
  • -

#6 samuel17   User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 209
  • Joined: 14-October 10

Re: Inserting a row at runtime

Posted 17 October 2010 - 02:43 PM

Have you done much with this before? Basically this is suppose to be like a college database, keep track of students, courses they are enrolled in and that stuff. I put a listview in there and it does look great, that you for that, but when i try to do an insert and click the insert button the page refreshes and nothing happens, it doesnt get added. I read on one of the links about going into the advanced button under the configure data source and having to generate a update, insert, and whatever else but that is only if the source is from only one table and mine is built from multiple tables through the query builder so there is no advanced button to do the generating of those items. When you go to specify a custom SQL statement and build your query it shows all of the select statements and other items and i have that copied into the "SELECT" "UPDATE" "INSERT" and "DELETE" tabs so im not sure what else might need to be done to get this to update correctly. The fields by the insert row all say "Databound" so it should be linked in. Hope you can help me some more, you have been very helpful so far Nakor.

Thanks much,
Sam
Was This Post Helpful? 0
  • +
  • -

#7 Nakor   User is offline

  • Professional Lurker
  • member icon

Reputation: 448
  • View blog
  • Posts: 1,504
  • Joined: 28-April 09

Re: Inserting a row at runtime

Posted 17 October 2010 - 07:19 PM

One way to overcome this is to change the insert button so that it is not working through the datasource, but instead calls a method you create in the codebehind. You can do this by changing the codename of the insert button to something else. For this example I'll name it InsertItem instead.

 <InsertItemTemplate>
            <tr style="">
                <td>
                    <asp:Button ID="InsertButton" runat="server" CommandName="InsertItem" 
                        Text="Insert" />
                    <asp:Button ID="CancelButton" runat="server" CommandName="Cancel" 
                        Text="Clear" />
                </td>



Next you'll want to configure the ListView to perform an action on the ItemCommand event. The easiest way to do this is to go into the ListItem event properties and type the method name into the ItemCommand field. Once you do that Visual Studio will automatically create the method stub in the codebehind. In my example I'll name this method "runCommand". So the ListView should look something similar to this...

<asp:ListView ID="ListView1" runat="server" DataKeyNames="InvoiceID" 
        DataSourceID="SqlDataSource2" InsertItemPosition="LastItem" OnItemCommand="runCommand">



and your codebehind should have a method like this...

    protected void runCommand(object sender, ListViewCommandEventArgs e)
    {

    }



Now to point get the method to recognize that the event called is the insert event we'll look for the command name "InsertItem".

    protected void runCommand(object sender, ListViewCommandEventArgs e)
    {
        if (e.CommandName.CompareTo("InsertItem").Equals(0))
        {
            // To read the values in the listview we use the Item property of e
            TextBox tb = (TextBox)e.Item.FindControl("textboxID");
            // In here create your own insert code to insert the info from the listview
        }
    }


This post has been edited by Nakor: 17 October 2010 - 07:51 PM

Was This Post Helpful? 0
  • +
  • -

#8 samuel17   User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 209
  • Joined: 14-October 10

Re: Inserting a row at runtime

Posted 18 October 2010 - 10:44 AM

Hi Nakor,
again i appreciate your assistance. Before getting to in depth and trying to do this i just want to make sure i am following you. First, what do you mean by back code? Is that just like the source coding behind the design part of things? Also for your line:
TextBox tb = (TextBox)e.Item.FindControl("textboxID");
Is the first part "TextBox" just a variable name? What is the "tb" part? Is (TextBox) just a type declaration? and the last ("textboxID") is that what the field name is? such as if my field name was courseID mine would be ("courseID") instead of ("textboxID")?
Again i appreciate your assistance and for being patient with me while i am trying to learn this.

Thanks,
Sam
Was This Post Helpful? 0
  • +
  • -

#9 Nakor   User is offline

  • Professional Lurker
  • member icon

Reputation: 448
  • View blog
  • Posts: 1,504
  • Joined: 28-April 09

Re: Inserting a row at runtime

Posted 18 October 2010 - 04:12 PM

// TextBox is the class, tb is the name of the variable
// So here we are creating a variable named tb of type TextBox
// Since we are wanting to get the value of a textbox from the ListView
// we use the FindControl method and search for the ID of the control.
// We use (TextBox) in front of it to cast the returned control as a
// TextBox type. If the control you are trying to get a value from is
// a DropDownList then you would just change TextBox to DropDownList
// in both places.

TextBox tb = (TextBox)e.Item.FindControl("textboxID");

/*
I'll try to break it down a little...

TextBox tb : Declares a variable of type TextBox

(TextBox) : casts the code it is next to as a TextBox type, this will cause an error if the control that is found is not a textbox

e.Item.FindControl : search the current ListView Item for a specific control

("textboxID") : This will be whatever you put as the ID of the control, could be TextBox1 or whatever you may have named it
*/ 



Biggest thing to remember is that when you are trying to cast the found control into a specific control type is that the type must match the control type in the form. If in the listview the control is a text box then use TextBox, if the control in the listview is a dropdownlist then use DropDownList and so on. You can't cast a control that is a TextBox into a DropDownList.

Hopefully, that made sense, I can ramble sometimes. :P
Was This Post Helpful? 0
  • +
  • -

#10 samuel17   User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 209
  • Joined: 14-October 10

Re: Inserting a row at runtime

Posted 19 October 2010 - 09:29 AM

Hi Nakor,
Thanks, i really appreciate the explanation. It does help alot and it does make sense. One more thing though so I would be putting this all in the right spot. What is the back code? Is this the same area that all the code goes or is it a special area? That probably sounds stupid haha i just want to get this all done the right way and have less stress with doing it the wrong way. Thanks again.

Sam
Was This Post Helpful? 0
  • +
  • -

#11 Nakor   User is offline

  • Professional Lurker
  • member icon

Reputation: 448
  • View blog
  • Posts: 1,504
  • Joined: 28-April 09

Re: Inserting a row at runtime

Posted 19 October 2010 - 10:11 AM

it's the same area. It's the "code behind" the page
Was This Post Helpful? 0
  • +
  • -

#12 samuel17   User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 209
  • Joined: 14-October 10

Re: Inserting a row at runtime

Posted 19 October 2010 - 12:35 PM

Hi Nakor,
Does that work for VB. No matter what i do with that it doesnt work, nor does it like the curly braces, which i know is used for java and C. Im not sure if it will help but i could paste me code. Im not sure what else to try.

Sam
Was This Post Helpful? 0
  • +
  • -

#13 Nakor   User is offline

  • Professional Lurker
  • member icon

Reputation: 448
  • View blog
  • Posts: 1,504
  • Joined: 28-April 09

Re: Inserting a row at runtime

Posted 19 October 2010 - 12:37 PM

the code i pasted was for C# but it shouldn't require much changing to get it to work in vb, paste your code and we can see, though i've not worked much in VB
Was This Post Helpful? 0
  • +
  • -

#14 samuel17   User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 209
  • Joined: 14-October 10

Re: Inserting a row at runtime

Posted 19 October 2010 - 01:38 PM

I tried doing some changing, but i think part of my problem is that im not quite sure where to put the code either, no matter where i put it i get a compiling error. Its getting stressful. Here is the code:
<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

    Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)

    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)

    End Sub
    
    
    </script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">
        #form1
        {
            background-color: #6699FF;
        }
        .style1
        {
            font-size: xx-large;
        }
        </style>
</head>
<body bgcolor="#000000" style="background-color: #6699FF">
    <form id="form1" runat="server">
    <div style="background-color: #6699FF">
    
        <span class="style1"><strong>Courses</strong></span><br />
    
        <asp:ListBox ID="ListBox1" runat="server" AutoPostBack="True" 
            DataSourceID="SqlDataSource2" DataTextField="coursenum" 
            DataValueField="courseid" BackColor="Black" ForeColor="Red" 
            style="font-weight: 700; color: #000000; background-color: #FFFFFF;"></asp:ListBox>
        <asp:SqlDataSource ID="SqlDataSource2" runat="server" 
            ConnectionString="<%$ ConnectionStrings:CampusConnectionString %>" 


            
            SelectCommand="SELECT DISTINCT [courseid], [coursenum] FROM [courses] ORDER BY [coursenum]"></asp:SqlDataSource>
    
    </div>
    <asp:ListView ID="ListView1" runat="server" DataKeyNames="courseid" 
        DataSourceID="SqlDataSource1" InsertItemPosition="LastItem"
        OnItemCommand="runCommand">

        protected void runCommand(object sender, ListViewCommandEventArgs e)
    
     if (e.CommandName.CompareTo("InsertItem").Equals(0))
        
            
            TextBox tb = (TextBox)e.Item.FindControl("textboxID");
    
               
        
        
            <AlternatingItemTemplate>
            <tr style="">
                <td>
                    <asp:Button ID="DeleteButton" runat="server" CommandName="Delete" 
                        Text="Delete" />
                    <asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
                </td>
                <td>
                    <asp:Label ID="yearsemLabel" runat="server" Text='<%# Eval("yearsem") %>' />
                </td>
                <td>
                    <asp:Label ID="creditsLabel" runat="server" Text='<%# Eval("credits") %>' />
                </td>
                <td>
                    <asp:Label ID="courseidLabel" runat="server" Text='<%# Eval("courseid") %>' />
                </td>
                <td>
                    <asp:Label ID="firstnameLabel" runat="server" Text='<%# Eval("firstname") %>' />
                </td>
                <td>
                    <asp:Label ID="lastnameLabel" runat="server" Text='<%# Eval("lastname") %>' />
                </td>
            </tr>
        </AlternatingItemTemplate>
        <EditItemTemplate>
            <tr style="">
                <td>
                    <asp:Button ID="UpdateButton" runat="server" CommandName="Update" 
                        Text="Update" />
                    <asp:Button ID="CancelButton" runat="server" CommandName="Cancel" 
                        Text="Cancel" />
                </td>
                <td>
                    <asp:TextBox ID="yearsemTextBox" runat="server" Text='<%# Bind("yearsem") %>' />
                </td>
                <td>
                    <asp:TextBox ID="creditsTextBox" runat="server" Text='<%# Bind("credits") %>' />
                </td>
                <td>
                    <asp:Label ID="courseidLabel1" runat="server" Text='<%# Eval("courseid") %>' />
                </td>
                <td>
                    <asp:TextBox ID="firstnameTextBox" runat="server" 
                        Text='<%# Bind("firstname") %>' />
                </td>
                <td>
                    <asp:TextBox ID="lastnameTextBox" runat="server" 
                        Text='<%# Bind("lastname") %>' />
                </td>
            </tr>
        </EditItemTemplate>
        <EmptyDataTemplate>
            <table runat="server" style="">
                <tr>
                    <td>
                        No data was returned.</td>
                </tr>
            </table>
        </EmptyDataTemplate>
        <InsertItemTemplate>
            <tr style="">
                <td>
                    <asp:Button ID="InsertButton" runat="server" CommandName="InsertItem" 
                        Text="Insert" />
                    <asp:Button ID="CancelButton" runat="server" CommandName="Cancel" 
                        Text="Clear" />
                </td>
                <td>
                    <asp:TextBox ID="yearsemTextBox" runat="server" 
                        Text='<%# Bind("yearsem") %>' />
                </td>
                <td>
                    <asp:TextBox ID="creditsTextBox" runat="server" 
                        Text='<%# Bind("credits") %>' />
                </td>
                <td>
                    <asp:TextBox ID="courseidTextBox" runat="server" 
                        Text='<%# Bind("courseid") %>' />
                </td>
                <td>
                    <asp:TextBox ID="firstnameTextBox" runat="server" 
                        Text='<%# Bind("firstname") %>' />
                </td>
                <td>
                    <asp:TextBox ID="lastnameTextBox" runat="server" 
                        Text='<%# Bind("lastname") %>' />
                </td>
            </tr>
        </InsertItemTemplate>
        <ItemTemplate>
            <tr style="">
                <td>
                    <asp:Button ID="DeleteButton" runat="server" CommandName="Delete" 
                        Text="Delete" />
                    <asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
                </td>
                <td>
                    <asp:Label ID="yearsemLabel" runat="server" Text='<%# Eval("yearsem") %>' />
                </td>
                <td>
                    <asp:Label ID="creditsLabel" runat="server" Text='<%# Eval("credits") %>' />
                </td>
                <td>
                    <asp:Label ID="courseidLabel" runat="server" Text='<%# Eval("courseid") %>' />
                </td>
                <td>
                    <asp:Label ID="firstnameLabel" runat="server" Text='<%# Eval("firstname") %>' />
                </td>
                <td>
                    <asp:Label ID="lastnameLabel" runat="server" Text='<%# Eval("lastname") %>' />
                </td>
            </tr>
        </ItemTemplate>
        <LayoutTemplate>
            <table runat="server">
                <tr runat="server">
                    <td runat="server">
                        <table ID="itemPlaceholderContainer" runat="server" border="1" style="1 font-size: xx-large; color: #000000; font-size: xx-large; font-weight: bold; text-align: center;">
                            <tr runat="server" style="">
                                <th runat="server">
                                </th>
                                <th runat="server">
                                    yearsem</th>
                                <th runat="server">
                                    credits</th>
                                <th runat="server">
                                    courseid</th>
                                <th runat="server">
                                    firstname</th>
                                <th runat="server">
                                    lastname</th>
                            </tr>
                            <tr ID="itemPlaceholder" runat="server">
                            </tr>
                        </table>
                    </td>
                </tr>
                <tr runat="server">
                    <td runat="server" style="">
                        <asp:DataPager ID="DataPager1" runat="server">
                            <Fields>
                                <asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True" 
                                    ShowLastPageButton="True" />
                            </Fields>
                        </asp:DataPager>
                    </td>
                </tr>
            </table>
        </LayoutTemplate>
        <SelectedItemTemplate>
            <tr style="">
                <td>
                    <asp:Button ID="DeleteButton" runat="server" CommandName="Delete" 
                        Text="Delete" />
                    <asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
                </td>
                <td>
                    <asp:Label ID="yearsemLabel" runat="server" Text='<%# Eval("yearsem") %>' />
                </td>
                <td>
                    <asp:Label ID="creditsLabel" runat="server" Text='<%# Eval("credits") %>' />
                </td>
                <td>
                    <asp:Label ID="courseidLabel" runat="server" Text='<%# Eval("courseid") %>' />
                </td>
                <td>
                    <asp:Label ID="firstnameLabel" runat="server" Text='<%# Eval("firstname") %>' />
                </td>
                <td>
                    <asp:Label ID="lastnameLabel" runat="server" Text='<%# Eval("lastname") %>' />
                </td>
            </tr>
        </SelectedItemTemplate>
    </asp:ListView>
    <br />
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:CampusConnectionString %>" 
        
        
        SelectCommand="SELECT courses.yearsem, courses.credits, courses.courseid, [Enrolled Students].firstname, [Enrolled Students].lastname FROM courses INNER JOIN [Enrolled Students] ON courses.courseid = [Enrolled Students].course_id WHERE (courses.courseid = @courseid)" 
        DeleteCommand="SELECT courses.yearsem, courses.credits, courses.courseid, [Enrolled Students].firstname, [Enrolled Students].lastname FROM courses INNER JOIN [Enrolled Students] ON courses.courseid = [Enrolled Students].course_id WHERE (courses.courseid = @courseid)" 
        InsertCommand="SELECT courses.yearsem, courses.credits, courses.courseid, [Enrolled Students].firstname, [Enrolled Students].lastname FROM courses INNER JOIN [Enrolled Students] ON courses.courseid = [Enrolled Students].course_id WHERE (courses.courseid = @courseid)" 
        UpdateCommand="SELECT courses.yearsem, courses.credits, courses.courseid, [Enrolled Students].firstname, [Enrolled Students].lastname FROM courses INNER JOIN [Enrolled Students] ON courses.courseid = [Enrolled Students].course_id WHERE (courses.courseid = @courseid)">
        <DeleteParameters>
            <asp:Parameter Name="courseid" />
        </DeleteParameters>
        <InsertParameters>
            <asp:Parameter Name="courseid" />
        </InsertParameters>
        <SelectParameters>
            <asp:ControlParameter ControlID="ListBox1" Name="courseid" 
                PropertyName="SelectedValue" />
        </SelectParameters>
        <UpdateParameters>
            <asp:Parameter Name="courseid" />
        </UpdateParameters>
    </asp:SqlDataSource>
     
    </form>
</body>
</html>



Thanks,
Sam
Was This Post Helpful? 0
  • +
  • -

#15 Nakor   User is offline

  • Professional Lurker
  • member icon

Reputation: 448
  • View blog
  • Posts: 1,504
  • Joined: 28-April 09

Re: Inserting a row at runtime

Posted 19 October 2010 - 02:18 PM

Not 100% sure on this, but it should be close. I'm just not real sure how casting is done in VB

<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

    Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)

    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)

    End Sub
    
    'This is the runCommand being called by the ListView when the insert button is clicked
    Protected Sub runCommand(ByVal sender As Object, ByVal e As ListViewCommandEventArgs)
        If e.CommandName.CompareTo("InsertItem").Equals(0) Then
            Dim tb As TextBox = TryCast(e.Item.FindControl("yearsemTextBox"), TextBox)
            tb.Text = "This is just a test"
        End If
    End Sub
    </script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <style type="text/css">
        #form1
        {
            background-color: #6699FF;
        }
        .style1
        {
            font-size: xx-large;
        }
        </style>
</head>
<body bgcolor="#000000" style="background-color: #6699FF">
    <form id="form1" runat="server">
    <div style="background-color: #6699FF">
    
        <span class="style1"><strong>Courses</strong></span><br />
    
        <asp:ListBox ID="ListBox1" runat="server" AutoPostBack="True" 
            DataSourceID="SqlDataSource2" DataTextField="coursenum" 
            DataValueField="courseid" BackColor="Black" ForeColor="Red" 
            style="font-weight: 700; color: #000000; background-color: #FFFFFF;"></asp:ListBox>
        <asp:SqlDataSource ID="SqlDataSource2" runat="server" 
            ConnectionString="<%$ ConnectionStrings:CampusConnectionString %>" 


            
            SelectCommand="SELECT DISTINCT [courseid], [coursenum] FROM [courses] ORDER BY [coursenum]"></asp:SqlDataSource>
    
    </div>
    <asp:ListView ID="ListView1" runat="server" DataKeyNames="courseid" 
        DataSourceID="SqlDataSource1" InsertItemPosition="LastItem"
        OnItemCommand="runCommand">       
            <AlternatingItemTemplate>
            <tr style="">
                <td>
                    <asp:Button ID="DeleteButton" runat="server" CommandName="Delete" 
                        Text="Delete" />
                    <asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
                </td>
                <td>
                    <asp:Label ID="yearsemLabel" runat="server" Text='<%# Eval("yearsem") %>' />
                </td>
                <td>
                    <asp:Label ID="creditsLabel" runat="server" Text='<%# Eval("credits") %>' />
                </td>
                <td>
                    <asp:Label ID="courseidLabel" runat="server" Text='<%# Eval("courseid") %>' />
                </td>
                <td>
                    <asp:Label ID="firstnameLabel" runat="server" Text='<%# Eval("firstname") %>' />
                </td>
                <td>
                    <asp:Label ID="lastnameLabel" runat="server" Text='<%# Eval("lastname") %>' />
                </td>
            </tr>
        </AlternatingItemTemplate>
        <EditItemTemplate>
            <tr style="">
                <td>
                    <asp:Button ID="UpdateButton" runat="server" CommandName="Update" 
                        Text="Update" />
                    <asp:Button ID="CancelButton" runat="server" CommandName="Cancel" 
                        Text="Cancel" />
                </td>
                <td>
                    <asp:TextBox ID="yearsemTextBox" runat="server" Text='<%# Bind("yearsem") %>' />
                </td>
                <td>
                    <asp:TextBox ID="creditsTextBox" runat="server" Text='<%# Bind("credits") %>' />
                </td>
                <td>
                    <asp:Label ID="courseidLabel1" runat="server" Text='<%# Eval("courseid") %>' />
                </td>
                <td>
                    <asp:TextBox ID="firstnameTextBox" runat="server" 
                        Text='<%# Bind("firstname") %>' />
                </td>
                <td>
                    <asp:TextBox ID="lastnameTextBox" runat="server" 
                        Text='<%# Bind("lastname") %>' />
                </td>
            </tr>
        </EditItemTemplate>
        <EmptyDataTemplate>
            <table id="Table1" runat="server" style="">
                <tr>
                    <td>
                        No data was returned.</td>
                </tr>
            </table>
        </EmptyDataTemplate>
        <InsertItemTemplate>
            <tr style="">
                <td>
                    <asp:Button ID="InsertButton" runat="server" CommandName="InsertItem" 
                        Text="Insert" />
                    <asp:Button ID="CancelButton" runat="server" CommandName="Cancel" 
                        Text="Clear" />
                </td>
                <td>
                    <asp:TextBox ID="yearsemTextBox" runat="server" 
                        Text='<%# Bind("yearsem") %>' />
                </td>
                <td>
                    <asp:TextBox ID="creditsTextBox" runat="server" 
                        Text='<%# Bind("credits") %>' />
                </td>
                <td>
                    <asp:TextBox ID="courseidTextBox" runat="server" 
                        Text='<%# Bind("courseid") %>' />
                </td>
                <td>
                    <asp:TextBox ID="firstnameTextBox" runat="server" 
                        Text='<%# Bind("firstname") %>' />
                </td>
                <td>
                    <asp:TextBox ID="lastnameTextBox" runat="server" 
                        Text='<%# Bind("lastname") %>' />
                </td>
            </tr>
        </InsertItemTemplate>
        <ItemTemplate>
            <tr style="">
                <td>
                    <asp:Button ID="DeleteButton" runat="server" CommandName="Delete" 
                        Text="Delete" />
                    <asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
                </td>
                <td>
                    <asp:Label ID="yearsemLabel" runat="server" Text='<%# Eval("yearsem") %>' />
                </td>
                <td>
                    <asp:Label ID="creditsLabel" runat="server" Text='<%# Eval("credits") %>' />
                </td>
                <td>
                    <asp:Label ID="courseidLabel" runat="server" Text='<%# Eval("courseid") %>' />
                </td>
                <td>
                    <asp:Label ID="firstnameLabel" runat="server" Text='<%# Eval("firstname") %>' />
                </td>
                <td>
                    <asp:Label ID="lastnameLabel" runat="server" Text='<%# Eval("lastname") %>' />
                </td>
            </tr>
        </ItemTemplate>
        <LayoutTemplate>
            <table id="Table2" runat="server">
                <tr id="Tr1" runat="server">
                    <td id="Td1" runat="server">
                        <table ID="itemPlaceholderContainer" runat="server" border="1" style="1 font-size: xx-large; color: #000000; font-size: xx-large; font-weight: bold; text-align: center;">
                            <tr id="Tr2" runat="server" style="">
                                <th id="Th1" runat="server">
                                </th>
                                <th id="Th2" runat="server">
                                    yearsem</th>
                                <th id="Th3" runat="server">
                                    credits</th>
                                <th id="Th4" runat="server">
                                    courseid</th>
                                <th id="Th5" runat="server">
                                    firstname</th>
                                <th id="Th6" runat="server">
                                    lastname</th>
                            </tr>
                            <tr ID="itemPlaceholder" runat="server">
                            </tr>
                        </table>
                    </td>
                </tr>
                <tr id="Tr3" runat="server">
                    <td id="Td2" runat="server" style="">
                        <asp:DataPager ID="DataPager1" runat="server">
                            <Fields>
                                <asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True" 
                                    ShowLastPageButton="True" />
                            </Fields>
                        </asp:DataPager>
                    </td>
                </tr>
            </table>
        </LayoutTemplate>
        <SelectedItemTemplate>
            <tr style="">
                <td>
                    <asp:Button ID="DeleteButton" runat="server" CommandName="Delete" 
                        Text="Delete" />
                    <asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
                </td>
                <td>
                    <asp:Label ID="yearsemLabel" runat="server" Text='<%# Eval("yearsem") %>' />
                </td>
                <td>
                    <asp:Label ID="creditsLabel" runat="server" Text='<%# Eval("credits") %>' />
                </td>
                <td>
                    <asp:Label ID="courseidLabel" runat="server" Text='<%# Eval("courseid") %>' />
                </td>
                <td>
                    <asp:Label ID="firstnameLabel" runat="server" Text='<%# Eval("firstname") %>' />
                </td>
                <td>
                    <asp:Label ID="lastnameLabel" runat="server" Text='<%# Eval("lastname") %>' />
                </td>
            </tr>
        </SelectedItemTemplate>
    </asp:ListView>
    <br />
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:CampusConnectionString %>" 
        
        
        SelectCommand="SELECT courses.yearsem, courses.credits, courses.courseid, [Enrolled Students].firstname, [Enrolled Students].lastname FROM courses INNER JOIN [Enrolled Students] ON courses.courseid = [Enrolled Students].course_id WHERE (courses.courseid = @courseid)" 
        DeleteCommand="SELECT courses.yearsem, courses.credits, courses.courseid, [Enrolled Students].firstname, [Enrolled Students].lastname FROM courses INNER JOIN [Enrolled Students] ON courses.courseid = [Enrolled Students].course_id WHERE (courses.courseid = @courseid)" 
        InsertCommand="SELECT courses.yearsem, courses.credits, courses.courseid, [Enrolled Students].firstname, [Enrolled Students].lastname FROM courses INNER JOIN [Enrolled Students] ON courses.courseid = [Enrolled Students].course_id WHERE (courses.courseid = @courseid)" 
        UpdateCommand="SELECT courses.yearsem, courses.credits, courses.courseid, [Enrolled Students].firstname, [Enrolled Students].lastname FROM courses INNER JOIN [Enrolled Students] ON courses.courseid = [Enrolled Students].course_id WHERE (courses.courseid = @courseid)">
        <DeleteParameters>
            <asp:Parameter Name="courseid" />
        </DeleteParameters>
        <InsertParameters>
            <asp:Parameter Name="courseid" />
        </InsertParameters>
        <SelectParameters>
            <asp:ControlParameter ControlID="ListBox1" Name="courseid" 
                PropertyName="SelectedValue" />
        </SelectParameters>
        <UpdateParameters>
            <asp:Parameter Name="courseid" />
        </UpdateParameters>
    </asp:SqlDataSource>
     
    </form>
</body>
</html>


Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2