M
Mike Robbins
I'm trying to find an article that will help me use a dropdownlist in a
GridView and have the selecteditem set appropriately in the ddl.
<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False" DataSourceID="odsRooms">
<Columns>
<asp:TemplateField HeaderText="LeaseID"
SortExpression="LeaseID">
<EditItemTemplate>
<aspropDownList ID="DropDownList1" runat="server"
DataSourceID="odsLeases"
DataTextField="LeaseName"
DataValueField="LeaseID">
</aspropDownList>
</EditItemTemplate>
<ItemTemplate>
<aspropDownList ID="DropDownList1"
runat="server" DataSourceID="odsLeases"
DataTextField="LeaseName"
DataValueField="LeaseID">
</aspropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="RoomID" HeaderText="RoomID"
SortExpression="RoomID" />
<asp:BoundField DataField="RoomName" HeaderText="RoomName"
SortExpression="RoomName" />
<asp:BoundField DataField="RoomOrder" HeaderText="RoomOrder"
SortExpression="RoomOrder" />
<asp:BoundField DataField="Active" HeaderText="Active"
SortExpression="Active" />
</Columns>
</asp:GridView>
<asp:ObjectDataSource ID="odsRooms" runat="server"
SelectMethod="GetList" TypeName="Room">
</asp:ObjectDataSource>
<asp:ObjectDataSource ID="odsLeases" runat="server"
SelectMethod="GetLeases" TypeName="Lease">
</asp:ObjectDataSource>
All of the ddls show as having the first item selected. How do you bind the
ddl's DataValueField to the GridView's LeaseID value for each row?
Thanks.
Mike
public class Room
{
private long m_RoomID;
private long m_LeaseID;
private string m_RoomName;
private int m_RoomOrder;
private int m_Active;
public long RoomID
{
get { return (m_RoomID); }
set {m_RoomID = value;}
}
public long LeaseID
{
get { return (m_LeaseID); }
set { m_LeaseID = value; }
}
public string RoomName
{
get { return (m_RoomName); }
set { m_RoomName = value; }
}
public int RoomOrder
{
get { return (m_RoomOrder); }
set { m_RoomOrder = value; }
}
public int Active
{
get { return (m_Active); }
set { m_Active = value; }
}
public Room()
{
//
// TODO: Add constructor logic here
//
}
public List<Room> GetList(long leaseID)
{
OracleConnection roomConnection = new OracleConnection("user
id=test;password=test;data source=test;persist security info=False");
OracleCommand roomCommand = new OracleCommand("SELECT * FROM
Rooms");
OracleDataReader roomData;
roomCommand.CommandType = CommandType.Text;
roomCommand.Connection = roomConnection;
roomConnection.Open();
roomData = roomCommand.ExecuteReader();
List<Room> RoomList = new List<Room>();
while (roomData.Read())
{
Room thisRoom = new Room();
thisRoom.RoomID = roomData.GetInt32(0);
thisRoom.LeaseID = roomData.GetInt32(1);
thisRoom.RoomName = roomData.GetString(2);
thisRoom.RoomOrder = roomData.GetInt32(3);
thisRoom.Active = roomData.GetInt32(4);
RoomList.Add(thisRoom);
}
roomConnection.Close();
return RoomList;
}
}
public class Lease
{
private long m_LeaseID;
private string m_LeaseName;
private string m_Description;
private int m_Active;
public long LeaseID
{
get { return (m_LeaseID); }
set { m_LeaseID = value; }
}
public string LeaseName
{
get { return (m_LeaseName); }
set { m_LeaseName = value; }
}
public string Description
{
get { return (m_Description); }
set { m_Description = value; }
}
public int Active
{
get { return (m_Active); }
set { m_Active = value; }
}
public Lease()
{
}
public List<Lease> GetLeases()
{
OracleConnection leaseConnection = new OracleConnection("user
id=test;password=test;data source=test;persist security info=False");
OracleCommand leaseCommand = new OracleCommand("SELECT LeaseID,
LeaseName, Description, Active FROM Leases");
OracleDataReader leaseData;
leaseCommand.CommandType = CommandType.Text;
leaseCommand.Connection = leaseConnection;
leaseConnection.Open();
leaseData = leaseCommand.ExecuteReader();
List<Lease> LeaseList = new List<Lease>();
while (leaseData.Read())
{
Lease thisLease = new Lease();
thisLease.LeaseID = leaseData.GetInt32(0);
thisLease.LeaseName = leaseData.GetString(1);
thisLease.Description = leaseData.GetString(2);
thisLease.Active = leaseData.GetInt32(3);
LeaseList.Add(thisLease);
}
leaseConnection.Close();
return LeaseList;
}
}
GridView and have the selecteditem set appropriately in the ddl.
<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False" DataSourceID="odsRooms">
<Columns>
<asp:TemplateField HeaderText="LeaseID"
SortExpression="LeaseID">
<EditItemTemplate>
<aspropDownList ID="DropDownList1" runat="server"
DataSourceID="odsLeases"
DataTextField="LeaseName"
DataValueField="LeaseID">
</aspropDownList>
</EditItemTemplate>
<ItemTemplate>
<aspropDownList ID="DropDownList1"
runat="server" DataSourceID="odsLeases"
DataTextField="LeaseName"
DataValueField="LeaseID">
</aspropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="RoomID" HeaderText="RoomID"
SortExpression="RoomID" />
<asp:BoundField DataField="RoomName" HeaderText="RoomName"
SortExpression="RoomName" />
<asp:BoundField DataField="RoomOrder" HeaderText="RoomOrder"
SortExpression="RoomOrder" />
<asp:BoundField DataField="Active" HeaderText="Active"
SortExpression="Active" />
</Columns>
</asp:GridView>
<asp:ObjectDataSource ID="odsRooms" runat="server"
SelectMethod="GetList" TypeName="Room">
</asp:ObjectDataSource>
<asp:ObjectDataSource ID="odsLeases" runat="server"
SelectMethod="GetLeases" TypeName="Lease">
</asp:ObjectDataSource>
All of the ddls show as having the first item selected. How do you bind the
ddl's DataValueField to the GridView's LeaseID value for each row?
Thanks.
Mike
public class Room
{
private long m_RoomID;
private long m_LeaseID;
private string m_RoomName;
private int m_RoomOrder;
private int m_Active;
public long RoomID
{
get { return (m_RoomID); }
set {m_RoomID = value;}
}
public long LeaseID
{
get { return (m_LeaseID); }
set { m_LeaseID = value; }
}
public string RoomName
{
get { return (m_RoomName); }
set { m_RoomName = value; }
}
public int RoomOrder
{
get { return (m_RoomOrder); }
set { m_RoomOrder = value; }
}
public int Active
{
get { return (m_Active); }
set { m_Active = value; }
}
public Room()
{
//
// TODO: Add constructor logic here
//
}
public List<Room> GetList(long leaseID)
{
OracleConnection roomConnection = new OracleConnection("user
id=test;password=test;data source=test;persist security info=False");
OracleCommand roomCommand = new OracleCommand("SELECT * FROM
Rooms");
OracleDataReader roomData;
roomCommand.CommandType = CommandType.Text;
roomCommand.Connection = roomConnection;
roomConnection.Open();
roomData = roomCommand.ExecuteReader();
List<Room> RoomList = new List<Room>();
while (roomData.Read())
{
Room thisRoom = new Room();
thisRoom.RoomID = roomData.GetInt32(0);
thisRoom.LeaseID = roomData.GetInt32(1);
thisRoom.RoomName = roomData.GetString(2);
thisRoom.RoomOrder = roomData.GetInt32(3);
thisRoom.Active = roomData.GetInt32(4);
RoomList.Add(thisRoom);
}
roomConnection.Close();
return RoomList;
}
}
public class Lease
{
private long m_LeaseID;
private string m_LeaseName;
private string m_Description;
private int m_Active;
public long LeaseID
{
get { return (m_LeaseID); }
set { m_LeaseID = value; }
}
public string LeaseName
{
get { return (m_LeaseName); }
set { m_LeaseName = value; }
}
public string Description
{
get { return (m_Description); }
set { m_Description = value; }
}
public int Active
{
get { return (m_Active); }
set { m_Active = value; }
}
public Lease()
{
}
public List<Lease> GetLeases()
{
OracleConnection leaseConnection = new OracleConnection("user
id=test;password=test;data source=test;persist security info=False");
OracleCommand leaseCommand = new OracleCommand("SELECT LeaseID,
LeaseName, Description, Active FROM Leases");
OracleDataReader leaseData;
leaseCommand.CommandType = CommandType.Text;
leaseCommand.Connection = leaseConnection;
leaseConnection.Open();
leaseData = leaseCommand.ExecuteReader();
List<Lease> LeaseList = new List<Lease>();
while (leaseData.Read())
{
Lease thisLease = new Lease();
thisLease.LeaseID = leaseData.GetInt32(0);
thisLease.LeaseName = leaseData.GetString(1);
thisLease.Description = leaseData.GetString(2);
thisLease.Active = leaseData.GetInt32(3);
LeaseList.Add(thisLease);
}
leaseConnection.Close();
return LeaseList;
}
}