关于datagrid的问题,急救!!!!!!!

yuqinke 2007-06-06 06:59:17
我在datagrid里面写如下代码显示数据:
<ItemTemplate>
<asp:DropDownList id="DropDownList2" runat="server">
<asp:ListItem><%#DataBinder.Eval(Container.DataItem,"stuanswer")%></asp:ListItem>
</asp:DropDownList>
</Itemtemplate>
但就是读不出来,急,汗呀!

帮帮忙,为什么读不出来????

分析器错误信息: 此上下文中不支持代码块

该如何修改才可以读出来?
...全文
209 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
Jinglecat 2007-06-06
  • 打赏
  • 举报
回复
Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid1.ItemDataBound
If e.Item.ItemType = ListItemType.EditItem Then
Dim ddll As DropDownList = CType(e.Item.FindControl("DropDownList2"), DropDownList)
ddll.DataSource = Dtemp.Tables(PageId)
ddll.DataTextField = "stuanswer" 'name
ddll.DataValueField = "Id" 'id
ddll.DataBind()
ddll.Items.FindByValue(Convert.ToString(DataBinder.Eval(e.Item.DataItem, "stuanswer"))).Selected = True
End If
End Sub

-------------
方向对了,但是,

If e.Item.ItemType = ListItemType.EditItem Then

>>>>

If e.Item.ItemType = ListItemType.Item OR e.Item.ItemType = ListItemType.AlternatingItem OR e.Item.ItemType = ListItemType.EditItem

youthkin 2007-06-06
  • 打赏
  • 举报
回复
分页用在datagrid里很简单
一句代码搞定
this.datagrid1.currentpageindex=e.newpageindex;
但数据源要用dataadapter并在属性生成器中将允许分页打勾
choudoufu 2007-06-06
  • 打赏
  • 举报
回复
是否可以用它作分页控件
lijia4 2007-06-06
  • 打赏
  • 举报
回复
或者用模板列也可以实现
lijia4 2007-06-06
  • 打赏
  • 举报
回复
老兄你用的是VB.NET呀,有点看不明白你的后台代码.


<asp:DropDownList id="DropDownList2" runat="server">
<asp:ListItem><%#DataBinder.Eval(Container.DataItem,"stuanswer")%></asp:ListItem>
</asp:DropDownList>
放在DataGrid 的外面,

在后台写

DropDownList2.DataSource=dr;
DropDownList2.DataTextField="stuanswer";
DropDownList2.DataValueField="stuanswer";
DropDownList2.DataBind();
这是C#的你可以参考一下.
amandag 2007-06-06
  • 打赏
  • 举报
回复
你这里既然是<ItemTemplate>

绑定当然是
If e.Item.ItemType = ListItemType.Item And e.Item.ItemType = ListItemType.AlternatingItem Then
...
yuqinke 2007-06-06
  • 打赏
  • 举报
回复
我顶
yuqinke 2007-06-06
  • 打赏
  • 举报
回复
Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid1.ItemDataBound
If e.Item.ItemType = ListItemType.EditItem Then
Dim ddll As DropDownList = CType(e.Item.FindControl("DropDownList2"), DropDownList)
ddll.DataSource = Dtemp.Tables(PageId)
ddll.DataTextField = "stuanswer" 'name
ddll.DataValueField = "Id" 'id
ddll.DataBind()
ddll.Items.FindByValue(Convert.ToString(DataBinder.Eval(e.Item.DataItem, "stuanswer"))).Selected = True
End If
End Sub

但我这样也不行呀,我晕了。。。。。。
amandag 2007-06-06
  • 打赏
  • 举报
回复
不能这样绑定数据项
<ItemTemplate>
<asp:DropDownList id="DropDownList2" runat="server">
</asp:DropDownList>
</Itemtemplate>

在后台的ItemDataBound方法中绑定DropDownList2的数据

62,025

社区成员

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

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

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

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