Quantcast
Channel: Visual Studio and Visual Web Developer Express
Viewing all articles
Browse latest Browse all 3509

Using a drop down list for entering data in just one of the columns of an editable listview

$
0
0

[Edit, added after posting]: The preview showed a graphic but the post itself doesn't. Sorry. I will see if I can fix it. I just tried again using the "post image from word" button. It previews correctly but doesn't post the image.

I'm new to this, trying out Visual Web Developer 2010 with C# background code. I have a little learning database with a couple of tables. One of the tables is Teams and another is Schedule. In making out the schedule I want to use a drop down list from Teams when I enter the opponents in the schedule, but not for any of the other columns in the Schedule list. I have created a Listview in Schedule.aspx with EDIT/DELETE/INSERT/CLEAR capability and also created a dropdown list. This much works but I don't know how to integrate the dropdown list so that it shows up in a cell when I click on it to enter an opponent.

I'm also new to this list so we will see below if I can successfully post an image and code. Here's an image:

Game

Date

OpponentTeam

GameID

<input type="submit" value="Delete" name="ListView1$ctrl0$DeleteButton" /> <input type="submit" value="Edit" name="ListView1$ctrl0$EditButton" />

1

6/1/2015 12:00:00 AM

Mesa

1

<input type="submit" value="Delete" name="ListView1$ctrl1$DeleteButton" /> <input type="submit" value="Edit" name="ListView1$ctrl1$EditButton" />

2

6/8/2015 12:00:00 AM

Scottsdale

2

<input type="submit" value="Delete" name="ListView1$ctrl2$DeleteButton" /> <input type="submit" value="Edit" name="ListView1$ctrl2$EditButton" />

3

6/9/2015 12:00:00 AM

Tempe

3

<input type="submit" value="Insert" name="ListView1$ctrl3$InsertButton" /> <input type="submit" value="Clear" name="ListView1$ctrl3$CancelButton" />

<input type="text" name="ListView1$ctrl3$GameTextBox" />

<input type="text" name="ListView1$ctrl3$DateTextBox" />

<input type="text" name="ListView1$ctrl3$OpponentTeamTextBox" />

<input type="text" name="ListView1$ctrl3$GameIDTextBox" />

         

OK, that worked. Now I will try showing the generated code:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Schedule.aspx.cs" Inherits="Schedule" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"><title></title></head><body><form id="form1" runat="server"><div></div><asp:ListView ID="ListView1" runat="server" DataKeyNames="GameID" 
        DataSourceID="SqlDataSource1" InsertItemPosition="LastItem"><AlternatingItemTemplate><tr style="background-color: #FFFFFF;color: #284775;"><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="GameLabel" runat="server" Text='<%# Eval("Game") %>' /></td><td><asp:Label ID="DateLabel" runat="server" Text='<%# Eval("Date") %>' /></td><td><asp:Label ID="OpponentTeamLabel" runat="server" 
                        Text='<%# Eval("OpponentTeam") %>' /></td><td><asp:Label ID="GameIDLabel" runat="server" Text='<%# Eval("GameID") %>' /></td></tr></AlternatingItemTemplate><EditItemTemplate><tr style="background-color: #999999;"><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="GameTextBox" runat="server" Text='<%# Bind("Game") %>' /></td><td><asp:TextBox ID="DateTextBox" runat="server" Text='<%# Bind("Date") %>' /></td><td><asp:TextBox ID="OpponentTeamTextBox" runat="server" 
                        Text='<%# Bind("OpponentTeam") %>' /></td><td><asp:Label ID="GameIDLabel1" runat="server" Text='<%# Eval("GameID") %>' /></td></tr></EditItemTemplate><EmptyDataTemplate><table runat="server" 
                style="background-color: #FFFFFF;border-collapse: collapse;border-color: #999999;border-style:none;border-width:1px;"><tr><td>
                        No data was returned.</td></tr></table></EmptyDataTemplate><InsertItemTemplate><tr style=""><td><asp:Button ID="InsertButton" runat="server" CommandName="Insert" 
                        Text="Insert" /><asp:Button ID="CancelButton" runat="server" CommandName="Cancel" 
                        Text="Clear" /></td><td><asp:TextBox ID="GameTextBox" runat="server" Text='<%# Bind("Game") %>' /></td><td><asp:TextBox ID="DateTextBox" runat="server" Text='<%# Bind("Date") %>' /></td><td><asp:TextBox ID="OpponentTeamTextBox" runat="server" 
                        Text='<%# Bind("OpponentTeam") %>' /></td><td><asp:TextBox ID="GameIDTextBox" runat="server" Text='<%# Bind("GameID") %>' /></td></tr></InsertItemTemplate><ItemTemplate><tr style="background-color: #E0FFFF;color: #333333;"><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="GameLabel" runat="server" Text='<%# Eval("Game") %>' /></td><td><asp:Label ID="DateLabel" runat="server" Text='<%# Eval("Date") %>' /></td><td><asp:Label ID="OpponentTeamLabel" runat="server" 
                        Text='<%# Eval("OpponentTeam") %>' /></td><td><asp:Label ID="GameIDLabel" runat="server" Text='<%# Eval("GameID") %>' /></td></tr></ItemTemplate><LayoutTemplate><table runat="server"><tr runat="server"><td runat="server"><table ID="itemPlaceholderContainer" runat="server" border="1" 
                            style="background-color: #FFFFFF;border-collapse: collapse;border-color: #999999;border-style:none;border-width:1px;font-family: Verdana, Arial, Helvetica, sans-serif;"><tr runat="server" style="background-color: #E0FFFF;color: #333333;"><th runat="server"></th><th runat="server">
                                    Game</th><th runat="server">
                                    Date</th><th runat="server">
                                    OpponentTeam</th><th runat="server">
                                    GameID</th></tr><tr ID="itemPlaceholder" runat="server"></tr></table></td></tr><tr runat="server"><td runat="server" 
                        style="text-align: center;background-color: #5D7B9D;font-family: Verdana, Arial, Helvetica, sans-serif;color: #FFFFFF"></td></tr></table></LayoutTemplate><SelectedItemTemplate><tr style="background-color: #E2DED6;font-weight: bold;color: #333333;"><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="GameLabel" runat="server" Text='<%# Eval("Game") %>' /></td><td><asp:Label ID="DateLabel" runat="server" Text='<%# Eval("Date") %>' /></td><td><asp:Label ID="OpponentTeamLabel" runat="server" 
                        Text='<%# Eval("OpponentTeam") %>' /></td><td><asp:Label ID="GameIDLabel" runat="server" Text='<%# Eval("GameID") %>' /></td></tr></SelectedItemTemplate></asp:ListView><asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:BaseballConnectionString %>" 
        DeleteCommand="DELETE FROM [Schedule] WHERE [GameID] = @GameID" 
        InsertCommand="INSERT INTO [Schedule] ([Game], [Date], [OpponentTeam]) VALUES (@Game, @Date, @OpponentTeam)" 
        SelectCommand="SELECT * FROM [Schedule]" 
        UpdateCommand="UPDATE [Schedule] SET [Game] = @Game, [Date] = @Date, [OpponentTeam] = @OpponentTeam WHERE [GameID] = @GameID"><DeleteParameters><asp:Parameter Name="GameID" Type="Byte" /></DeleteParameters><InsertParameters><asp:Parameter Name="Game" Type="Byte" /><asp:Parameter DbType="Date" Name="Date" /><asp:Parameter Name="OpponentTeam" Type="String" /></InsertParameters><UpdateParameters><asp:Parameter Name="Game" Type="Byte" /><asp:Parameter DbType="Date" Name="Date" /><asp:Parameter Name="OpponentTeam" Type="String" /><asp:Parameter Name="GameID" Type="Byte" /></UpdateParameters></asp:SqlDataSource><asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="Teams" 
        DataTextField="TeamName" DataValueField="TeamName"></asp:DropDownList><asp:SqlDataSource ID="Teams" runat="server" 
        ConnectionString="<%$ ConnectionStrings:BaseballConnectionString %>" 
        SelectCommand="SELECT [TeamName] FROM [Teams]"></asp:SqlDataSource></form></body></html>

I don't know if it's too much to ask here, but I would certainly appreciate any help someone can give to show me how to integrate the dropdown list into the OpponentTeam cells when one tries to edit them. Thanks in advance.

--Lynn


Viewing all articles
Browse latest Browse all 3509

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>