自定义控件页面的代码 NewAddControl.ascx
if (!IsPostBack)
{
int nid = Convert.ToInt32(Request.QueryString["nid"]);
string strsql = "select Cid,Ccaption from navFrist";
NewsClass ns = new NewsClass();
DataTable ds = ns.GetMessageList(strsql);
DropDownList1.DataSource = ds;
DropDownList1.DataTextField = "Ccaption";
DropDownList1.DataValueField = "cid";
DropDownList1.DataBind();
DropDownList1.Items.Insert(0, new ListItem("请选择栏目", "0"));
}
自定义控件里还有一个按钮 单击按钮 得不到cDropDownList1的值
protected void Button1_Click(object sender, EventArgs e)
{
NewsClass nad = new NewsClass();
nad.content = DropDownList1.SelectedValue; }
而且如果不加!IsPostBack DropDownList1.SelectedValue的值始终为0 加上就没有任何值,我的页面是调用模板运行的
跟踪运行DropDownList1当提交以后就没有任何值了,不知道是在什么时候丢失的值?
帮我看看是什么问题 谢谢!
if (!IsPostBack)
{
int nid = Convert.ToInt32(Request.QueryString["nid"]);
string strsql = "select Cid,Ccaption from navFrist";
NewsClass ns = new NewsClass();
DataTable ds = ns.GetMessageList(strsql);
DropDownList1.DataSource = ds;
DropDownList1.DataTextField = "Ccaption";
DropDownList1.DataValueField = "cid";
DropDownList1.DataBind();
DropDownList1.Items.Insert(0, new ListItem("请选择栏目", "0"));
}
自定义控件里还有一个按钮 单击按钮 得不到cDropDownList1的值
protected void Button1_Click(object sender, EventArgs e)
{
NewsClass nad = new NewsClass();
nad.content = DropDownList1.SelectedValue; }
而且如果不加!IsPostBack DropDownList1.SelectedValue的值始终为0 加上就没有任何值,我的页面是调用模板运行的
跟踪运行DropDownList1当提交以后就没有任何值了,不知道是在什么时候丢失的值?
帮我看看是什么问题 谢谢!
我试过是行的//WEB控件代码
protected void Button1_Click(object sender, EventArgs e)
{
string a=this.DropDownList1.SelectedValue;
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
SqlConnection conn = new SqlConnection("*******");
SqlCommand cmd = new SqlCommand("select * from c_propertytype", conn);
System.Data.DataTable dt = new System.Data.DataTable();
using (SqlDataAdapter da = new SqlDataAdapter(cmd))
{
conn.Open();
da.Fill(dt);
conn.Close();
}
this.DropDownList1.DataTextField= "propertytypename";
this.DropDownList1.DataValueField = "propertytypeid";
this.DropDownList1.DataSource = dt;
this.DropDownList1.DataBind();
this.DropDownList1.Items.Insert(0, new ListItem("请选择栏目", "0")); }
//页面中没有写任何代码.如果你的页面的viewstate关闭了的话是不行的.
MasterPage.master
-------------------------------------------------------
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="manage_master_MasterPage" %>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页 </title>
</head>
<body style="margin-top:0; margin-left:0;">
<div>
<table border="0" cellpadding="0" cellspacing="0" style="width: 100%; height: 100%">
<tr>
<td style="height: 214px" valign=top>
<div class="" id="rightChannel">
<form id="form1" runat="server">
<asp:contentplaceholder id="ContentPlaceHolder1" runat="server">
</asp:contentplaceholder>
</form>
</div>
</td>
</tr>
<tr>
<td colspan="2" style="height: 200px">
</td>
</tr>
</table>
</div>
</body>
</html> 调用页面admin_navmoid.aspx
<%@ Page Language="C#" MasterPageFile="~/manage/master/MasterPage.master" AutoEventWireup="true" CodeFile="admin_navmoid.aspx.cs" Inherits="manage_master_admin_navmoid" Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<ul>
<li class="title sysColor_bg1 sysTitle" style="height:30px;" >栏目管理 </li> <li class="item" style="width:200px; float:left; text-align:left">
<div>现栏目名称: </div>
<div> <asp:ListBox ID="ListBox1" runat="server" Height="300px" Width="200px" AutoPostBack="true" OnSelectedIndexChanged="ListBox1_SelectedIndexChanged1"> </asp:ListBox> </div>
</li>
<li class="item" style="width:200px; float:left; text-align:left">
<div>修改栏目名称: </div>
<div class="sysColor_bg4 nav" style=" width:100%; height:300px; border:1px solid #959595;">
<table width="388" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td height="25" valign="top" style="width: 118px; font-size:12px;" align="right">栏目名称: </td>
<td valign="top" style="width: 259px"> <asp:TextBox ID="Ccaption" runat="server"> </asp:TextBox> <!--DWLayoutEmptyCell--> </td>
</tr>
<tr>
<td height="25" valign="top" style="width: 118px;font-size:12px;" align="right">栏目配图: </td>
<td valign="top" style="width: 259px">
<asp:FileUpload ID="FileUpload1" runat="server" /> <!--DWLayoutEmptyCell--> </td>
</tr>
<tr>
<td height="25" valign="top" style="width: 118px" align="right"> <!--DWLayoutEmptyCell--> </td>
<td valign="top" style="width: 259px"> <!--DWLayoutEmptyCell--> <asp:Button ID="Button1" runat="server" Text="修改" /> </td>
</tr>
<tr>
<td valign="top" style="width: 118px; height: 25px;font-size:12px;" align="right">录入时间: </td>
<td valign="top" style="width: 259px; height: 25px;font-size:12px;"> </td>
</tr>
<tr>
<td height="25" valign="top" style="width: 118px;font-size:12px;" align="right">现有栏目配图: </td>
<td valign="top" style="width: 259px;font-size:12px;"> </td>
</tr>
</table>
</div>
</li>
</ul>
</asp:Content>