天啊,可以正常浏览,<ItemTemplate>是正确的,但点击编辑按钮时(<EditItemTemplate>),却发生了下面这个错误,救命啊,急啊!!!!!!!!!
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。源错误:
行 45: public int GetPriceIndex(string PriceName)
行 46: {
行 47: if (PriceIndex[PriceName] != null)
行 48: return (int)PriceIndex[PriceName];
行 49: else
源文件: c:\wk\webapplicationcsharp\webform1.aspx.cs 行: 47 ASPX文件<asp:TemplateColumn HeaderText="金额单位">
<ItemTemplate>
<asp:DropDownList id="Dropdownlist2" runat="server" SelectedIndex='<%# GetPriceIndex(DataBinder.Eval(Container.DataItem, "price_type").ToString()) %>'>
<asp:ListItem Value="0">人民币</asp:ListItem>
<asp:ListItem Value="1">美元</asp:ListItem>
<asp:ListItem Value="2">港币</asp:ListItem>
</asp:DropDownList> </FONT>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList id="Dropdownlist1" runat="server" SelectedIndex='<%# GetPriceIndex(DataBinder.Eval(Container.DataItem, "price_type").ToString()) %>'>
<asp:ListItem Value="0">人民币</asp:ListItem>
<asp:ListItem Value="1">美元</asp:ListItem>
<asp:ListItem Value="2">港币</asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>CS文件:public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataGrid DataGrid1;
public Hashtable PriceIndex;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if (!IsPostBack)
{ PriceIndex = new Hashtable();
PriceIndex["0"] = 0;
PriceIndex["1"] = 1;
PriceIndex["2"] = 2;
BindGridToSource();
}
}
public int GetPriceIndex(string PriceName)
{
if (PriceIndex[PriceName] != null)
return (int)PriceIndex[PriceName];
else
return 0;
}
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。源错误:
行 45: public int GetPriceIndex(string PriceName)
行 46: {
行 47: if (PriceIndex[PriceName] != null)
行 48: return (int)PriceIndex[PriceName];
行 49: else
源文件: c:\wk\webapplicationcsharp\webform1.aspx.cs 行: 47 ASPX文件<asp:TemplateColumn HeaderText="金额单位">
<ItemTemplate>
<asp:DropDownList id="Dropdownlist2" runat="server" SelectedIndex='<%# GetPriceIndex(DataBinder.Eval(Container.DataItem, "price_type").ToString()) %>'>
<asp:ListItem Value="0">人民币</asp:ListItem>
<asp:ListItem Value="1">美元</asp:ListItem>
<asp:ListItem Value="2">港币</asp:ListItem>
</asp:DropDownList> </FONT>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList id="Dropdownlist1" runat="server" SelectedIndex='<%# GetPriceIndex(DataBinder.Eval(Container.DataItem, "price_type").ToString()) %>'>
<asp:ListItem Value="0">人民币</asp:ListItem>
<asp:ListItem Value="1">美元</asp:ListItem>
<asp:ListItem Value="2">港币</asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>CS文件:public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataGrid DataGrid1;
public Hashtable PriceIndex;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if (!IsPostBack)
{ PriceIndex = new Hashtable();
PriceIndex["0"] = 0;
PriceIndex["1"] = 1;
PriceIndex["2"] = 2;
BindGridToSource();
}
}
public int GetPriceIndex(string PriceName)
{
if (PriceIndex[PriceName] != null)
return (int)PriceIndex[PriceName];
else
return 0;
}
解决方案 »
- TreeView重绘问题,还请大家帮帮忙
- 可以在程序中修改控件的大小吗?比如修改datagridview表格的大小
- C#中的方法签名是什么啊?
- 2个iframe之间的传值与获取!
- 紧急求助!请问拿到一个asp.net的C#写的web程序,怎么配置才能运行,指在iis里等等,我不是特别清楚,帮帮我!
- 问一个菜问题,别笑话
- 有谁知道截消息时的具体的代码吗?比如窗口最大化的是多少,etc....(好东西大家共享)
- 求求各位老大们给回答一下吧,真快急死了,我已经找这样的文章1星期了。
- 高分求助!关联表如何更新?
- 求rar , exe , jpg 等各种东西存SQLITE 数据库的完整代码!
- 急一个小问题,关于datagrid格式问题
- C#里怎样调用VB写的DLL啊?
把
PriceIndex = new Hashtable();
PriceIndex["0"] = 0;
PriceIndex["1"] = 1;
PriceIndex["2"] = 2;
BindGridToSource();
放到
!IsPostBack外面就ok了。