我在DataList中加个一个DroupDownList,然后在绑定时给DroupDownList绑定值,
我有个DroupDownList点击回传事件,这个DroupDownList在一个UpdatePanel局部更新中
但是相应事件的时候,出现未将对象引用到实例,请各位帮忙<td style="height:25px">
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td style="text-align:left; width:50px">
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
onselectedindexchanged="DropDownList1_SelectedIndexChanged">
</asp:DropDownList>
</td>
<td>
<asp:Label ID="txtPirce1" runat="server" Text='<%# GetMoney(Eval("Price1")) %>'></asp:Label>
<asp:Label ID="Label2" runat="server" Text='<%# GetMoney(Eval("Price1")) %>' Visible="false"></asp:Label>
预费:<asp:Label ID="txtFee1" runat="server" Text='<%#Eval("Fee1") %>'></asp:Label>
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
</td>
<%--这个是UpdateDatepanel在DataList一列中,里边包含一个DroupDownList和Label控件--%>
//加载绑定DroupDownList,前台可以显示
protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Label StartCount1 = e.Item.FindControl("txtStartCount1") as Label;
Label EndCount1 = e.Item.FindControl("txtEndCount1") as Label;
DropDownList DropDownList4 = e.Item.FindControl("DropDownList1") as DropDownList;
int end1 = 100;
if (EndCount1.Text != "不限制")
{
end1 = int.Parse(EndCount1.Text);
}
int start1 = int.Parse(StartCount1.Text.ToString());
int x = start1;
int count1 = end1 - start1 + 1;
for (int i = x; i < count1; i++)
{
string s = start1.ToString();
DropDownList4.Items.Insert(i - x, new ListItem(s));
start1++;
}
if (StartCount1.Text != "0")
{
DropDownList4.Items.Insert(0, new ListItem("0", "0"));
}
}
}
//回传DroupDownList,出现未将对象引用到实例。难道是我没取到这个控件?
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{ DropDownList DropDownList4 = DropDownList1.FindControl("DropDownList1") as DropDownList;//未将对象引用到实例
Label txtPirce1 = DataList1.FindControl("txtPirce1") as Label;
Label Label2 = DataList1.FindControl("Label2") as Label;
if (DropDownList4.SelectedItem.Text == "0")
{
txtPirce1.Text = Label2.Text;
}
else
{
txtPirce1.Text = (int.Parse(DropDownList4.SelectedItem.Text) * double.Parse(Label2.Text)).ToString();
}
}
我有个DroupDownList点击回传事件,这个DroupDownList在一个UpdatePanel局部更新中
但是相应事件的时候,出现未将对象引用到实例,请各位帮忙<td style="height:25px">
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td style="text-align:left; width:50px">
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
onselectedindexchanged="DropDownList1_SelectedIndexChanged">
</asp:DropDownList>
</td>
<td>
<asp:Label ID="txtPirce1" runat="server" Text='<%# GetMoney(Eval("Price1")) %>'></asp:Label>
<asp:Label ID="Label2" runat="server" Text='<%# GetMoney(Eval("Price1")) %>' Visible="false"></asp:Label>
预费:<asp:Label ID="txtFee1" runat="server" Text='<%#Eval("Fee1") %>'></asp:Label>
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
</td>
<%--这个是UpdateDatepanel在DataList一列中,里边包含一个DroupDownList和Label控件--%>
//加载绑定DroupDownList,前台可以显示
protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Label StartCount1 = e.Item.FindControl("txtStartCount1") as Label;
Label EndCount1 = e.Item.FindControl("txtEndCount1") as Label;
DropDownList DropDownList4 = e.Item.FindControl("DropDownList1") as DropDownList;
int end1 = 100;
if (EndCount1.Text != "不限制")
{
end1 = int.Parse(EndCount1.Text);
}
int start1 = int.Parse(StartCount1.Text.ToString());
int x = start1;
int count1 = end1 - start1 + 1;
for (int i = x; i < count1; i++)
{
string s = start1.ToString();
DropDownList4.Items.Insert(i - x, new ListItem(s));
start1++;
}
if (StartCount1.Text != "0")
{
DropDownList4.Items.Insert(0, new ListItem("0", "0"));
}
}
}
//回传DroupDownList,出现未将对象引用到实例。难道是我没取到这个控件?
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{ DropDownList DropDownList4 = DropDownList1.FindControl("DropDownList1") as DropDownList;//未将对象引用到实例
Label txtPirce1 = DataList1.FindControl("txtPirce1") as Label;
Label Label2 = DataList1.FindControl("Label2") as Label;
if (DropDownList4.SelectedItem.Text == "0")
{
txtPirce1.Text = Label2.Text;
}
else
{
txtPirce1.Text = (int.Parse(DropDownList4.SelectedItem.Text) * double.Parse(Label2.Text)).ToString();
}
}
解决方案 »
- 【请教】如何在前台获取 gridview 模板列 隐藏控件的值
- 如何设置datalist里的控件textbox的属性为只读?
- .net反编译的问题~~~~~~~~~~~~~~~~~~~~~
- asp.net文件移动
- asp.net的三层架构和mvc是同一个概念吗?
- AJAX的注册问题
- 超简单问题,如何给datalist中的label赋值?
- 有个asp.net的开源 电子商务系统,叫什么m**to的, 谁知道是什么啊?
- 帮忙,指点一下!Session问题??
- 如何用asp.net控制一系列图片在网页中有序显示?用何种控件可实现?
- 不做实际项目,不做大型项目,不做团队项目,你永远体会不了为什么要用三层,而且为什么非要用三层不可。
- 1000瓶汽水之生活版——为啥空瓶数可以为0!为啥可以借瓶子!
DropDownList DropDownList4 = up.FindControl("DropDownList1") as DropDownList;要先找到up,再从up找到ddl
必须的可以,
DropDownList DropDownList4 = sender as DropDownList 也可以
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{ DropDownList DropDownList4 = (DropDownList)sender; Response.Write(DropDownList4.Text);
}