icyer() 老大快来看看

baitianhai 2002-05-29 01:40:27
我用你的方法还是有问题
------------------------aspx程序
<asp:DropDownList id="DropDownList1" Runat="server"></asp:DropDownList>
------------------------vb程序
Private Sub DataList1_EditCommand()
Dim drop As DropDownList
drop = CType(e.Item.FindControl("DropDownList1"), DropDownList)
drop.Items.Add("asdfasd")
------------------------------------
报错:


未将对象引用设置到对象的实例。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。

异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。

源错误:


行 67: drop = CType(e.Item.FindControl("DropDownList1"), DropDownList)
行 68: drop.Items.Add("asdfasd")
行 69: DataList1.EditItemIndex = e.Item.ItemIndex


68行错误



...全文
103 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
baitianhai 2002-05-29
  • 打赏
  • 举报
回复
老大,你真是厉害,我解决了,太感谢了,能和你交个朋友吗?
你的QQ,mail能留给我吗?
我的是22329109
baichenhong@the9.com
icyer 2002-05-29
  • 打赏
  • 举报
回复
Sorry,刚才我没测试,你可以这样写:

DataList1.EditItemIndex = e.Item.ItemIndex
data_grid() '数据梆定的函数
Dim drop As DropDownList
drop = CType(DataList1.Items(e.Item.ItemIndex).FindControl("DropDownList1"), DropDownList)
drop.Items.Add("asdfasd")

以上代码我测试通过。
baitianhai 2002-05-29
  • 打赏
  • 举报
回复
icyer() 真的很感谢,可是我按照你的去做,还是提示
drop.Items.Add("asdfasd")这行
System.NullReferenceException: 未将对象引用设置到对象的实例。
我不知道该说什么好了
------------------------------aspx文件
<asp:DataList id="DataList1" runat="server">
<EditItemStyle></EditItemStyle>
<HeaderTemplate>
</HeaderTemplate>
<EditItemTemplate>
<table>
<tr width="300px">
<td>
<asp:LinkButton id="Linkbutton2" style="FONT-SIZE: 12px" Text="保存" CommandName="update" runat="server" /></asp:LinkButton></td>
<td>
<asp:LinkButton id="Linkbutton1" style="FONT-SIZE: 12px" Text="取消" CommandName="cancel" runat="server" /></asp:LinkButton></td>
</tr>
<tr width="300px" style="FONT-SIZE: 12px">
<td width="150px">
公司:
<asp:DropDownList id="DropDownList1" Runat="server"></asp:DropDownList><br>
<asp:TextBox id="Text1" Text='<%# DataBinder.Eval(Container, "DataItem.公司") %>' Runat=server Width="80px">
</asp:TextBox></td>
----------------------------------vb文件
Private Sub DataList1_EditCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataListCommandEventArgs) Handles DataList1.EditCommand
DataList1.EditItemIndex = e.Item.ItemIndex
data_grid() '数据梆定的函数
Dim drop As DropDownList
drop = CType(e.Item.FindControl("DropDownList1"), DropDownList)
drop.Items.Add("asdfasd")
End Sub


icyer 2002-05-29
  • 打赏
  • 举报
回复
DataList1.EditItemIndex = e.Item.ItemIndex
DataList1.DataBind()
Dim drop As DropDownList
drop = CType(e.Item.FindControl("DropDownList1"), DropDownList)
drop.Items.Add("asdfasd")
baitianhai 2002-05-29
  • 打赏
  • 举报
回复
我按你们说的做了还是有问题的,我该怎么办那????????
baitianhai 2002-05-29
  • 打赏
  • 举报
回复
两位老大我还是有问题
我已经在EditCommand中写了
DataList1.EditItemIndex = e.Item.ItemIndex
可是错误还是一样的,我该怎么办那?
baitianhai 2002-05-29
  • 打赏
  • 举报
回复
楼上的2位老大,真是万分感谢,可是你们看
未将对象引用设置到对象的实例。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。

异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。

源错误:

Private Sub DataList1_EditCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataListCommandEventArgs) Handles DataList1.EditCommand
行 67: DataList1.EditItemIndex = e.Item.ItemIndex
行 68: drop = CType(e.Item.FindControl("DropDownList1"), DropDownList)
行 69: drop.Items.Add("asdfasd")
行 70: 'dropdownlist2 = e.Item.FindControl("DropDownList1")


yxrj 2002-05-29
  • 打赏
  • 举报
回复
Private Sub DataList1_EditCommand()
Dim drop As DropDownList
drop = CType(e.Item.FindControl("DropDownList1"), DropDownList)
drop.Items.Add("asdfasd")

虽然你没完全写清楚
但一般人的做法是在edit模板里放dropdownlist
EditCommand刚执行的时候,dropdownlist应该是没有的
所以应该先设EditIndex
再绑定
最后再找dropdownlist
icyer 2002-05-29
  • 打赏
  • 举报
回复
那你先要把这一行设置成Edit行。
DataList1.EditItemIndex = e.Item.ItemIndex;
DataList1.DataBind();
然后再取DropDownList控件。
icyer 2002-05-29
  • 打赏
  • 举报
回复
那你先要把这一行设置成Edit行。
DataList1.EditItemIndex = e.Item.ItemIndex;
DataList1.DataBind();
然后再取DropDownList控件。
baitianhai 2002-05-29
  • 打赏
  • 举报
回复
e有Items这个属性
我是放在这里的
<asp:DataList id="DataList1" runat="server">
<EditItemStyle></EditItemStyle>
<HeaderTemplate>
</HeaderTemplate>
<EditItemTemplate>
<table>
<tr width="300px">
<td>
<asp:LinkButton id="Linkbutton2" style="FONT-SIZE: 12px" Text="保存" CommandName="update" runat="server" /></asp:LinkButton></td>
<td>
<asp:LinkButton id="Linkbutton1" style="FONT-SIZE: 12px" Text="取消" CommandName="cancel" runat="server" /></asp:LinkButton></td>
</tr>
<tr width="300px" style="FONT-SIZE: 12px">
<td width="150px">
公司:
<asp:DropDownList id="DropDownList1" Runat="server"></asp:DropDownList><br>
icyer 2002-05-29
  • 打赏
  • 举报
回复
e有Items这个属性吗?
你的DropDownList1是放在<ItemTemplate>...</ItemTemplate>中还是在<EditItemTemplate>..</EditItemTemplate>中?当前行是Edit行吗?
baitianhai 2002-05-29
  • 打赏
  • 举报
回复
那我怎么才能找到这个i那?帮忙了各位!
triout 2002-05-29
  • 打赏
  • 举报
回复
drop = CType(e.Item.FindControl("DropDownList1"), DropDownList)
修改为:
drop = CType(e.Items[i].FindControl("DropDownList1"), DropDownList)
这里的i值需要根据你触发事件的E来获取。
baitianhai 2002-05-29
  • 打赏
  • 举报
回复
老大,我还是有问题,你能给一个相应的例子吗?万分感谢!
icyer 2002-05-29
  • 打赏
  • 举报
回复
Dim drop As DropDownList
drop = CType(e.Item.FindControl("DropDownList1"), DropDownList)
If Not drop Is Nothing Then
drop.Items.Add("asdfasd")
End If
另外,如果当前行是Edit状态的话,就只显示<EditItemTemplate>..</EditItemTemplate>中的内容,否则就显示<ItemTemplate>...</ItemTemplate>中的内容。所以,你需要确认当前行的状态以及DropDownList在那种Template里面。
打开链接下载源码: https://pan.quark.cn/s/a4b39357ea24 在Qt框架中,QSerialPort类被视为一个关键组件,用于执行与串行端口之间的通信任务,它具备多样化的功能,涵盖了串口的开启与关闭操作,以及波特率、数据位、停止位和奇偶校验等参数的设定,同时还包括数据的发送和接收功能。在标题和描述中提及的“Qt5的QSerialPort类通过信号槽实现串口读写”,这代表了一种在Qt编程中普遍采用的事件驱动策略,借助信号槽机制,能够便捷地管理串口数据的传输与接收。 1. **QSerialPort类的基础操作**: - 初始化阶段:必须构建一个QSerialPort实例,并为其指定串口名称,例如"/dev/ttyUSB0"。 - 参数配置:利用`setPortName()`、`setBaudRate()`、`setDataBits()`、`setParity()`、`setStopBits()`、`setFlowControl()`等方法,依据具体需求对串口参数进行配置。 - 串口开启/终止:借助`open()`方法启动串口,通过`close()`方法终止串口。务必验证`isOpen()`的返回状态,以确保操作的有效性。 2. **信号槽机制的应用**: - 信号的生成:QSerialPort类中定义了若干信号,诸如`readyRead()`表明有数据可读,`error()`指示出现错误,`bytesWritten()`显示数据已传输等。当这些事件发生时,将触发相应的信号。 - 槽函数的关联:相应地,可以将这些信号与自定义的槽函数相连接,比如,当`readyRead()`信号被激活时,可以调用一个用于处理读取数据的函数。 3. **串口数据...

62,269

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧