过来看看!·!

zhaoliangpat 2003-08-25 03:15:38
下面的代码 ,当提示“只能选一个”的时候,会出现 Response.Write(CType(x.FindControl("getvalue"), Label).Text)的内容 怎么回事???


Dim x As DataGridItem
Dim i As Integer = 0
For Each x In DataGrid1.Items
If CType(x.FindControl("che"), CheckBox).Checked = True Then
i = i + 1
If i >= 2 Then
Response.Write("<script>alert('只能选一个');</script>")
Exit For
Exit Sub
response.end()
End If
Response.Write(CType(x.FindControl("getvalue"), Label).Text)
End If
Next
...全文
31 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
cnhgj 2003-08-28
  • 打赏
  • 举报
回复
我怎么没看到那事件的代码?
zhaoliangpat 2003-08-28
  • 打赏
  • 举报
回复
.aspx

<%@ Page Language="vb" AutoEventWireup="false" Codebehind="zimenu.aspx.vb" Inherits="wolfvod.zimenu"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WOLF.net视频点播系统</title>
<meta content="Microsoft Visual Studio .NET 7.0" name="GENERATOR">
<meta content="Visual Basic 7.0" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
</HEAD>
<body>
<FONT face="宋体">
<FORM id="Form1" method="post" runat="server">
<FONT face="宋体"></FONT> 
<TABLE id="Table1" style="WIDTH: 524px; HEIGHT: 415px" cellSpacing="0" cellPadding="0" width="524" align="center" border="0">
<TR>
<TD style="HEIGHT: 24px" align="middle"><asp:label id="Label1" runat="server" ForeColor="#C00000" Width="118px">菜单管理——</asp:label><asp:label id="Label2" runat="server" ForeColor="#C00000"></asp:label></TD>
</TR>
<TR>
<TD style="HEIGHT: 45px"><FONT face="宋体">        <INPUT style="WIDTH: 77px; COLOR: #ffffff; HEIGHT: 24px; BACKGROUND-COLOR: #cc0000" onclick="jacascript:history.go(-1)" type="button" value="返回" runat="server"> </FONT><FONT face="宋体"> 
<asp:button id="Button2" runat="server" Height="25px" ForeColor="White" BackColor="ActiveCaption" Width="80px" Text="增加"></asp:button>  
<asp:button id="Button3" runat="server" Height="25px" ForeColor="White" BackColor="ActiveCaption" Width="80px" Text="修改"></asp:button> 
<asp:button id="Button4" runat="server" Height="25px" ForeColor="White" BackColor="ActiveCaption" Width="80px" Text="删除"></asp:button></FONT></TD>
</TR>
<TR>
<TD vAlign="top">
<asp:datagrid id="DataGrid1" runat="server" Width="523px" BackColor="White" Height="20px" AutoGenerateColumns="False" CellPadding="4" BorderWidth="1px" BorderColor="#CC9966" AllowPaging="True" Font-Size="X-Small" BorderStyle="None" PageSize="5">
<SelectedItemStyle Font-Bold="True" ForeColor="#663399" BackColor="#FFCC66"></SelectedItemStyle>
<ItemStyle ForeColor="#330099" BackColor="White"></ItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="#FFFFCC" BackColor="#990000"></HeaderStyle>
<FooterStyle ForeColor="#330099" BackColor="#FFFFCC"></FooterStyle>
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<asp:CheckBox id="che" runat="server"></asp:CheckBox>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList id="DropDownList1" runat="server" Width="96px" AutoPostBack="True">
<asp:ListItem Value="2">2</asp:ListItem>
<asp:ListItem Value="1">1</asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="二级菜单">
<ItemTemplate>
<asp:label id="getvalue" runat="server" text='<%# DataBinder.Eval(Container,"DataItem.二级菜单")%>'>
</asp:label>
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="顺序" HeaderText="顺序"></asp:BoundColumn>
</Columns>
<PagerStyle HorizontalAlign="Center" ForeColor="#330099" BackColor="#FFFFCC" Mode="NumericPages"></PagerStyle>
</asp:datagrid></TD>
</TR>
</TABLE>
</FORM>
</FONT>
</body>
</HTML>



.vb


Imports System.Data.SqlClient
Imports System.Data
Imports System

Public Class zimenu
Inherits System.Web.UI.Page
Protected WithEvents Button4 As System.Web.UI.WebControls.Button
Protected WithEvents Button3 As System.Web.UI.WebControls.Button
Protected WithEvents Button2 As System.Web.UI.WebControls.Button
Protected WithEvents Label1 As System.Web.UI.WebControls.Label
Protected WithEvents Label2 As System.Web.UI.WebControls.Label
Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid
Protected WithEvents Button1 As System.Web.UI.HtmlControls.HtmlInputButton
Protected WithEvents Form1 As System.Web.UI.HtmlControls.HtmlForm

#Region " Web 窗体设计器生成的代码 "

'该调用是 Web 窗体设计器所必需的。
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

End Sub

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: 此方法调用是 Web 窗体设计器所必需的
'不要使用代码编辑器修改它。
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim id As String = Request.QueryString("zhucai")
Label2.Text = id

If Not IsPostBack Then
'判断是否有权限访问
If Session("yes") <> "yes" Then
Response.Redirect("error.aspx?number=1")
End If


'连接数据库信息
Dim str As String = ConfigurationSettings.AppSettings("conn")

Dim conn As SqlConnection
conn = New SqlConnection()
conn.ConnectionString = str
conn.Open()

'结束信息


Dim da As SqlDataAdapter
Dim ds As New DataSet()
Dim dv As DataTable

da = New SqlDataAdapter("select distinct ci as 二级菜单,shunxu1 as 顺序 from menu where zhu='" & id & "'", conn)
da.Fill(ds, "table1")
dv = ds.Tables("table1")
DataGrid1.DataSource = dv
DataGrid1.DataBind()
End If

'在此处放置初始化页的用户代码
End Sub



Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

End Sub




Private Sub DataGrid1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DataGrid1.SelectedIndexChanged

End Sub


Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

End Sub

Private Sub DataGrid1_PageIndexChanged(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles DataGrid1.PageIndexChanged
'连接数据库信息

Dim id As String = Request.QueryString("zhucai")

Dim str As String = ConfigurationSettings.AppSettings("conn")
Dim conn As SqlConnection
conn = New SqlConnection()
conn.ConnectionString = str
conn.Open()

'结束信息


Dim da As SqlDataAdapter
Dim ds As New DataSet()
Dim dv As DataTable

da = New SqlDataAdapter("select distinct ci as 二级菜单,shunxu1 as 顺序 from menu where zhu='" & id & "'", conn)
da.Fill(ds, "table1")
dv = ds.Tables("table1")
DataGrid1.DataSource = dv


DataGrid1.CurrentPageIndex = e.NewPageIndex
DataGrid1.DataBind()
End Sub

Private Sub Button1_ServerClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.ServerClick

End Sub
End Class
cnhgj 2003-08-27
  • 打赏
  • 举报
回复
把全部代码贴出来吧
Magicloud 2003-08-27
  • 打赏
  • 举报
回复
不知道你的目的是什么,看你的代码,你在exit sub后边,end if前还有代码,应该不会被执行。
如果要实现单选,可以将模版改为radiobutton,或变相使用selectitem。
cnhgj 2003-08-27
  • 打赏
  • 举报
回复
Dim x As DataGridItem
Dim i As Integer = 0
For Each x In DataGrid1.Items
If CType(x.FindControl("che"), CheckBox).Checked = True Then
i = i + 1
If i >= 2 Then
Response.Write("<script>alert('只能选一个');</script>")
Exit For
Exit Sub
end if
Next
For Each x In DataGrid1.Items
If CType(x.FindControl("che"), CheckBox).Checked = True Then
Response.Write(CType(x.FindControl("getvalue"), Label).Text)
End If
Next
cnhgj 2003-08-26
  • 打赏
  • 举报
回复
Dim x As DataGridItem
Dim i As Integer = 0
For Each x In DataGrid1.Items
If CType(x.FindControl("che"), CheckBox).Checked = True Then
i = i + 1
If i >= 2 Then
Response.Write("<script>alert('只能选一个');</script>")
Exit For
Exit Sub
response.end()
else
Response.Write(CType(x.FindControl("getvalue"), Label).Text)
end if
End If
Next
zhaoliangpat 2003-08-26
  • 打赏
  • 举报
回复
还是不好使呀!!!

62,025

社区成员

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

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

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

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