M
mpaine
Hello,
I am completely lost as to why I can't update a DropDownList inside a
DetailsView after I perform an insert into an object datasource. I tried to
simply it down to the core demostration:
default.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs"
Inherits="TestDetailsView.Default" %>
<!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" >
<body>
<form id="form1" runat="server">
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
DataObjectTypeName="TestDetailsView.User"
TypeName="TestDetailsView.UserAdapter" InsertMethod="InsertUser"
/>
<aspetailsView ID="DetailsView1" runat="server"
AutoGenerateRows="False" DataSourceID="ObjectDataSource1"
DefaultMode="Insert" OnItemInserting="DetailsView1_ItemInserting">
<Fields>
<asp:TemplateField HeaderText="Command" runat="server">
<ItemTemplate>
<aspropDownList ID="dv_ddlCommand" runat="server"
AutoPostBack="false">
<asp:ListItem Text="add"
Value="add"></asp:ListItem>
<asp:ListItem Text="delete"
Value="delete"></asp:ListItem>
</aspropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ButtonType="Button"
ShowInsertButton="True" InsertText="Add"></asp:CommandField>
</Fields>
</aspetailsView>
</form>
</body>
</html>
default.aspx.cs:
using System;
using System.Drawing;
using System.Web.UI.WebControls;
namespace TestDetailsView
{
public class User
{
private string _Command = "new";
public string Command
{
get { return _Command; }
set { _Command = value; }
}
public User() { }
public User(string Command)
{
this.Command = Command;
}
}
public class UserAdapter
{
public void InsertUser(User User)
{
}
}
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
DropDownList ddl =
(DropDownList)DetailsView1.FindControl("dv_ddlCommand");
if (ddl != null)
{
ddl.BackColor = Color.Red;
}
}
protected void DetailsView1_ItemInserting(object sender,
DetailsViewInsertEventArgs e)
{
DropDownList ddl =
(DropDownList)DetailsView1.FindControl("dv_ddlCommand");
if (ddl != null)
{
e.Values["Command"] = ddl.SelectedValue;
ddl.BackColor = Color.Red;
}
}
}
}
Any help would be extremely helpful.
Thank you!
I am completely lost as to why I can't update a DropDownList inside a
DetailsView after I perform an insert into an object datasource. I tried to
simply it down to the core demostration:
default.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs"
Inherits="TestDetailsView.Default" %>
<!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" >
<body>
<form id="form1" runat="server">
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
DataObjectTypeName="TestDetailsView.User"
TypeName="TestDetailsView.UserAdapter" InsertMethod="InsertUser"
/>
<aspetailsView ID="DetailsView1" runat="server"
AutoGenerateRows="False" DataSourceID="ObjectDataSource1"
DefaultMode="Insert" OnItemInserting="DetailsView1_ItemInserting">
<Fields>
<asp:TemplateField HeaderText="Command" runat="server">
<ItemTemplate>
<aspropDownList ID="dv_ddlCommand" runat="server"
AutoPostBack="false">
<asp:ListItem Text="add"
Value="add"></asp:ListItem>
<asp:ListItem Text="delete"
Value="delete"></asp:ListItem>
</aspropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ButtonType="Button"
ShowInsertButton="True" InsertText="Add"></asp:CommandField>
</Fields>
</aspetailsView>
</form>
</body>
</html>
default.aspx.cs:
using System;
using System.Drawing;
using System.Web.UI.WebControls;
namespace TestDetailsView
{
public class User
{
private string _Command = "new";
public string Command
{
get { return _Command; }
set { _Command = value; }
}
public User() { }
public User(string Command)
{
this.Command = Command;
}
}
public class UserAdapter
{
public void InsertUser(User User)
{
}
}
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
DropDownList ddl =
(DropDownList)DetailsView1.FindControl("dv_ddlCommand");
if (ddl != null)
{
ddl.BackColor = Color.Red;
}
}
protected void DetailsView1_ItemInserting(object sender,
DetailsViewInsertEventArgs e)
{
DropDownList ddl =
(DropDownList)DetailsView1.FindControl("dv_ddlCommand");
if (ddl != null)
{
e.Values["Command"] = ddl.SelectedValue;
ddl.BackColor = Color.Red;
}
}
}
}
Any help would be extremely helpful.
Thank you!