public void bianyi(object sender,EventArgs e) { foreach(DataGridItem m_item in this.DataGrid2.Items) {
int id=(int)this.DataGrid2.DataKeys[m_item.ItemIndex]; myconnclass myclass=new myconnclass(); Response.Redirect("detail.aspx?id="+id);
} }
public void bianyi(object sender,EventArgs e) { foreach(DataGridItem m_item in this.DataGrid2.Items) {
int id=(int)this.DataGrid2.DataKeys[m_item.ItemIndex]; myconnclass myclass=new myconnclass(); Response.Redirect("detail.aspx?id="+id);
} }
对vb不熟悉,具体的语法你自己去查查 Foreach DataGridItem item In datagrid.Items CheckBox chk=CType(item.FindControl("chk1"),CheckBox) End
对了,你要先试试你的单选按钮运行是否正常,是不是可以选择唯一的一个。我遇到过这样的问题使用<asp:radiobutton.......>时,单选按钮不能单选,要使用<input type="radio" value="<%# Container.ItemIndex %>"......>。要是使用<asp:radiobutton.......>可以, for i=0 to dcou.Items.Count-1 dim h as RadioButton h=Ctype(dcou.Items(i).Cells(0).Controls(1),RadioButton) if h.Checked = true then str1=dcou.Items(i).Cells(2).Text end if next 就行。其中str1就是你所选中行的某一个字段的值 要写在提交按钮的onclick事件中
For i = 0 To (c - 1) '从列表依次选取 每行 chkSelected = Nothing chkSelected = DataGrid1.Items(i).FindControl("ce1") chkselected1 = DataGrid1.Items(i).FindControl("ce2") If (Not (chkSelected Is Nothing)) Then '找到每行的复选框 If (chkSelected.Checked = True) Then '如果复选框被选中,更新此行的内容 End If end if next
For i = 0 To (c - 1) '从列表依次选取 每行 chkSelected = Nothing chkSelected = DataGrid1.Items(i).FindControl("ce1") chkselected1 = DataGrid1.Items(i).FindControl("ce2") If (Not (chkSelected Is Nothing)) Then '找到每行的复选框 If (chkSelected.Checked = True) Then '如果复选框被选中,更新此行的内容 End If end if next、 您给我回答的里面(c - 1)的C什么意思?("ce1")和("ce2")是不是字段呢!
dim c as integer =datagrid1.items.count cel、ce2为web控件的id
我这样写了:label1没有值啊!!!! Dim c As Integer = DataGrid1.Items.Count Dim i For i = 0 To (c - 1) '从列表依次选取 每行 Dim chkSelected Dim chkSelected1 chkSelected = Nothing chkSelected = DataGrid1.Items(i).FindControl("主菜单") chkSelected1 = DataGrid1.Items(i).FindControl("顺序") If (Not (chkSelected Is Nothing)) Then '找到每行的复选框 Label1.Text = chkSelected If (chkSelected.Checked = True) Then '如果复选框被选中,更新此行的内容 Label1.Text = chkSelected End If End If Next
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="ReLogin.aspx.vb" Inherits="dzwd.ReLogin"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <title>ReLogin</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 MS_POSITIONING="GridLayout"> <form id="Form1" method="post" runat="server"> <FONT face="宋体"></FONT> <asp:datagrid id="DataGrid1" style="Z-INDEX: 101; LEFT: 80px; POSITION: absolute; TOP: 68px" runat="server" BorderColor="#CC9966" BorderStyle="None" BorderWidth="1px" BackColor="White" CellPadding="4" AutoGenerateColumns="False" PageSize="5" Width="104px"> <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:BoundColumn DataField="username" HeaderText="主菜单"></asp:BoundColumn> </Columns> <PagerStyle HorizontalAlign="Center" ForeColor="#330099" BackColor="#FFFFCC"></PagerStyle> </asp:datagrid><asp:button id="Button1" style="Z-INDEX: 102; LEFT: 84px; POSITION: absolute; TOP: 32px" runat="server" Text="子菜单"></asp:button></form> </body> </HTML> ==================== .vb Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim i As Integer Dim c As Integer = DataGrid1.Items.Count Dim chkSelected As CheckBox For i = 0 To (c - 1) '从列表依次选取 每行 chkSelected = Nothing chkSelected = DataGrid1.Items(i).FindControl("che") If (Not (chkSelected Is Nothing)) Then '找到每行的复选框 If (chkSelected.Checked = True) Then '如果复选框被选中,更新此行的内容 Response.Write(DataGrid1.Items(i).Cells(1).Text) End If End If Next End Sub
guoyan19811021(吉祥)我按照你的方法做了 没有反映啊!!!<%@ Page Language="vb" AutoEventWireup="false" Codebehind="menu_info.aspx.vb" Inherits="wolfvod.menu_info"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <title>manage_info</title> <meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.0"> <meta name="CODE_LANGUAGE" content="Visual Basic 7.0"> <meta name="vs_defaultClientScript" content="JavaScript"> <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5"> </HEAD> <body> <FORM id="Form1" method="post" runat="server"> <FONT face="宋体"> <asp:Label id="Label1" runat="server">Label</asp:Label> <TABLE id="Table2" style="WIDTH: 393px; HEIGHT: 56px" cellSpacing="0" cellPadding="0" width="393" align="center" border="0"> <TR> <TD style="WIDTH: 373px; HEIGHT: 41px" height="41"> <asp:Button id="Button2" runat="server" Text="《子菜单》" Width="75px" Height="28px"></asp:Button> <asp:button id="Button1" runat="server" Text="《增 加》" Width="75px" Height="28px"></asp:button> <asp:Button id="Button3" runat="server" Text="《修 改》" Width="75px" Height="28px"></asp:Button> <asp:Button id="Button4" runat="server" Text="《删 除》" Width="75px" Height="28px"></asp:Button></TD> </TR> </TABLE> </FONT> <TABLE id="Table3" style="WIDTH: 227px; HEIGHT: 151px" cellSpacing="0" cellPadding="0" width="227" align="center" border="0"> <TR> <TD style="WIDTH: 155px; HEIGHT: 117px" vAlign="top" width="155"><FONT face="宋体"> <asp:DataGrid id="DataGrid1" runat="server" Width="391px" BorderColor="#3366CC" BorderStyle="None" BorderWidth="1px" BackColor="White" CellPadding="4" AllowPaging="True"> <SelectedItemStyle Font-Bold="True" ForeColor="#CCFF99" BackColor="#009999"></SelectedItemStyle> <ItemStyle ForeColor="#003399" BackColor="White"></ItemStyle> <HeaderStyle Font-Bold="True" ForeColor="#CCCCFF" BackColor="#003399"></HeaderStyle> <FooterStyle ForeColor="#003399" BackColor="#99CCCC"></FooterStyle> <Columns> <asp:TemplateColumn HeaderText="11" FooterText="11"> <ItemTemplate> <asp:CheckBox id="Checkbox1" 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> </Columns> <PagerStyle HorizontalAlign="Left" ForeColor="#003399" BackColor="#99CCCC" Mode="NumericPages"></PagerStyle> </asp:DataGrid></FONT></TD> </TR> </TABLE> </FORM> </body> </HTML>。vbImports System Imports System.Data Imports System.Data.SqlClientPublic Class menu_info Inherits System.Web.UI.Page Protected WithEvents Label1 As System.Web.UI.WebControls.Label Protected WithEvents Button2 As System.Web.UI.WebControls.Button Protected WithEvents Button1 As System.Web.UI.WebControls.Button Protected WithEvents Button3 As System.Web.UI.WebControls.Button Protected WithEvents Button4 As System.Web.UI.WebControls.Button Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid#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 '判断是否有权限访问 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 zhu as 主菜单,shunxu as 顺序 from menu ", conn) da.Fill(ds, "table1") dv = ds.Tables("table1") DataGrid1.DataSource = dv DataGrid1.DataBind() End Sub Private Sub DataGrid1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DataGrid1.SelectedIndexChanged
End Sub Private Sub DataGrid1_PageIndexChanged(ByVal source As System.Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) DataGrid1.CurrentPageIndex = e.NewPageIndex DataGrid1.DataBind() End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Response.Redirect("addmenu_zhu.aspx") End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim i As Integer Dim c As Integer = DataGrid1.Items.Count Dim chkSelected As CheckBox For i = 0 To (c - 1) '从列表依次选取 每行 chkSelected = Nothing chkSelected = DataGrid1.Items(i).FindControl("che") If (Not (chkSelected Is Nothing)) Then '找到每行的复选框 If (chkSelected.Checked = True) Then '如果复选框被选中,更新此行的内容 Response.Write(DataGrid1.Items(i).Cells(1).Text) End If End If Next End Sub Private Sub DataGrid1_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.ItemCommand End Sub End Class
{
foreach(DataGridItem m_item in this.DataGrid2.Items)
{
int id=(int)this.DataGrid2.DataKeys[m_item.ItemIndex];
myconnclass myclass=new myconnclass();
Response.Redirect("detail.aspx?id="+id);
} }
{
foreach(DataGridItem m_item in this.DataGrid2.Items)
{
int id=(int)this.DataGrid2.DataKeys[m_item.ItemIndex];
myconnclass myclass=new myconnclass();
Response.Redirect("detail.aspx?id="+id);
} }
Foreach DataGridItem item In datagrid.Items
CheckBox chk=CType(item.FindControl("chk1"),CheckBox)
End
for i=0 to dcou.Items.Count-1
dim h as RadioButton
h=Ctype(dcou.Items(i).Cells(0).Controls(1),RadioButton)
if h.Checked = true then
str1=dcou.Items(i).Cells(2).Text
end if
next
就行。其中str1就是你所选中行的某一个字段的值
要写在提交按钮的onclick事件中
'从列表依次选取 每行
chkSelected = Nothing
chkSelected = DataGrid1.Items(i).FindControl("ce1")
chkselected1 = DataGrid1.Items(i).FindControl("ce2") If (Not (chkSelected Is Nothing)) Then
'找到每行的复选框 If (chkSelected.Checked = True) Then
'如果复选框被选中,更新此行的内容 End If
end if
next
'从列表依次选取 每行
chkSelected = Nothing
chkSelected = DataGrid1.Items(i).FindControl("ce1")
chkselected1 = DataGrid1.Items(i).FindControl("ce2") If (Not (chkSelected Is Nothing)) Then
'找到每行的复选框 If (chkSelected.Checked = True) Then
'如果复选框被选中,更新此行的内容 End If
end if
next、
您给我回答的里面(c - 1)的C什么意思?("ce1")和("ce2")是不是字段呢!
cel、ce2为web控件的id
to:guoyan19811021(吉祥) chkSelected 是不是多选按牛的ID??
我把我的多选择按牛ID变成了chkSelected 为什么提示没有声明!!
Dim i
For i = 0 To (c - 1)
'从列表依次选取 每行
Dim chkSelected
Dim chkSelected1
chkSelected = Nothing
chkSelected = DataGrid1.Items(i).FindControl("主菜单")
chkSelected1 = DataGrid1.Items(i).FindControl("顺序") If (Not (chkSelected Is Nothing)) Then
'找到每行的复选框
Label1.Text = chkSelected
If (chkSelected.Checked = True) Then
'如果复选框被选中,更新此行的内容
Label1.Text = chkSelected End If
End If
Next
Dim chkSelected1
什么意思?
chkSelected = DataGrid1.Items(i).FindControl("")
chkSelected1 = DataGrid1.Items(i).FindControl("这里是在墨板列中的checkbox的id")
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>ReLogin</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 MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<FONT face="宋体"></FONT>
<asp:datagrid id="DataGrid1" style="Z-INDEX: 101; LEFT: 80px; POSITION: absolute; TOP: 68px" runat="server" BorderColor="#CC9966" BorderStyle="None" BorderWidth="1px" BackColor="White" CellPadding="4" AutoGenerateColumns="False" PageSize="5" Width="104px">
<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:BoundColumn DataField="username" HeaderText="主菜单"></asp:BoundColumn>
</Columns>
<PagerStyle HorizontalAlign="Center" ForeColor="#330099" BackColor="#FFFFCC"></PagerStyle>
</asp:datagrid><asp:button id="Button1" style="Z-INDEX: 102; LEFT: 84px; POSITION: absolute; TOP: 32px" runat="server" Text="子菜单"></asp:button></form>
</body>
</HTML>
====================
.vb Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim i As Integer
Dim c As Integer = DataGrid1.Items.Count
Dim chkSelected As CheckBox For i = 0 To (c - 1)
'从列表依次选取 每行
chkSelected = Nothing
chkSelected = DataGrid1.Items(i).FindControl("che")
If (Not (chkSelected Is Nothing)) Then
'找到每行的复选框 If (chkSelected.Checked = True) Then
'如果复选框被选中,更新此行的内容
Response.Write(DataGrid1.Items(i).Cells(1).Text) End If
End If
Next End Sub
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>manage_info</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.0">
<meta name="CODE_LANGUAGE" content="Visual Basic 7.0">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body>
<FORM id="Form1" method="post" runat="server">
<FONT face="宋体">
<asp:Label id="Label1" runat="server">Label</asp:Label>
<TABLE id="Table2" style="WIDTH: 393px; HEIGHT: 56px" cellSpacing="0" cellPadding="0" width="393" align="center" border="0">
<TR>
<TD style="WIDTH: 373px; HEIGHT: 41px" height="41">
<asp:Button id="Button2" runat="server" Text="《子菜单》" Width="75px" Height="28px"></asp:Button>
<asp:button id="Button1" runat="server" Text="《增 加》" Width="75px" Height="28px"></asp:button>
<asp:Button id="Button3" runat="server" Text="《修 改》" Width="75px" Height="28px"></asp:Button>
<asp:Button id="Button4" runat="server" Text="《删 除》" Width="75px" Height="28px"></asp:Button></TD>
</TR>
</TABLE>
</FONT>
<TABLE id="Table3" style="WIDTH: 227px; HEIGHT: 151px" cellSpacing="0" cellPadding="0" width="227" align="center" border="0">
<TR>
<TD style="WIDTH: 155px; HEIGHT: 117px" vAlign="top" width="155"><FONT face="宋体">
<asp:DataGrid id="DataGrid1" runat="server" Width="391px" BorderColor="#3366CC" BorderStyle="None" BorderWidth="1px" BackColor="White" CellPadding="4" AllowPaging="True">
<SelectedItemStyle Font-Bold="True" ForeColor="#CCFF99" BackColor="#009999"></SelectedItemStyle>
<ItemStyle ForeColor="#003399" BackColor="White"></ItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="#CCCCFF" BackColor="#003399"></HeaderStyle>
<FooterStyle ForeColor="#003399" BackColor="#99CCCC"></FooterStyle>
<Columns>
<asp:TemplateColumn HeaderText="11" FooterText="11">
<ItemTemplate>
<asp:CheckBox id="Checkbox1" 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>
</Columns>
<PagerStyle HorizontalAlign="Left" ForeColor="#003399" BackColor="#99CCCC" Mode="NumericPages"></PagerStyle>
</asp:DataGrid></FONT></TD>
</TR>
</TABLE>
</FORM>
</body>
</HTML>。vbImports System
Imports System.Data
Imports System.Data.SqlClientPublic Class menu_info
Inherits System.Web.UI.Page
Protected WithEvents Label1 As System.Web.UI.WebControls.Label
Protected WithEvents Button2 As System.Web.UI.WebControls.Button
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
Protected WithEvents Button3 As System.Web.UI.WebControls.Button
Protected WithEvents Button4 As System.Web.UI.WebControls.Button
Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid#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 '判断是否有权限访问
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 zhu as 主菜单,shunxu as 顺序 from menu ", conn)
da.Fill(ds, "table1")
dv = ds.Tables("table1")
DataGrid1.DataSource = dv
DataGrid1.DataBind() End Sub Private Sub DataGrid1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DataGrid1.SelectedIndexChanged
End Sub Private Sub DataGrid1_PageIndexChanged(ByVal source As System.Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs)
DataGrid1.CurrentPageIndex = e.NewPageIndex
DataGrid1.DataBind()
End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Response.Redirect("addmenu_zhu.aspx") End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim i As Integer
Dim c As Integer = DataGrid1.Items.Count
Dim chkSelected As CheckBox For i = 0 To (c - 1)
'从列表依次选取 每行
chkSelected = Nothing
chkSelected = DataGrid1.Items(i).FindControl("che")
If (Not (chkSelected Is Nothing)) Then
'找到每行的复选框 If (chkSelected.Checked = True) Then
'如果复选框被选中,更新此行的内容
Response.Write(DataGrid1.Items(i).Cells(1).Text) End If
End If
Next End Sub
Private Sub DataGrid1_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.ItemCommand End Sub
End Class