datagird问题!

zhaoliangpat 2003-08-20 11:49:58
datagird 里放个摸版列,放个单选按牛,我怎么才能获得这个单选按牛的一行的任意字段的值!!!!
...全文
97 21 打赏 收藏 转发到动态 举报
写回复
用AI写文章
21 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhaoliangpat 2003-08-23
  • 打赏
  • 举报
回复
高手谁帮忙呀!·!!
zhaoliangpat 2003-08-22
  • 打赏
  • 举报
回复
我这样写了: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
zhaoliangpat 2003-08-22
  • 打赏
  • 举报
回复

to:guoyan19811021(吉祥)

chkSelected 是不是多选按牛的ID??
我把我的多选择按牛ID变成了chkSelected 为什么提示没有声明!!
guoyan19811021 2003-08-22
  • 打赏
  • 举报
回复
dim c as integer =datagrid1.items.count
cel、ce2为web控件的id
zhaoliangpat 2003-08-22
  • 打赏
  • 举报
回复
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")是不是字段呢!
zhaoliangpat 2003-08-22
  • 打赏
  • 举报
回复
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>





。vb

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



Public 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




guoyan19811021 2003-08-22
  • 打赏
  • 举报
回复
<%@ 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
zhaoliangpat 2003-08-22
  • 打赏
  • 举报
回复


http://210.83.20.135/error.jpg

您看看图片!我想点击多选按牛,在点击子菜单,会出现多选按牛对应的“主菜单”的值,选几个就出现几个对应“主菜单”值!
guoyan19811021 2003-08-22
  • 打赏
  • 举报
回复
chkSelected,chkSelected1为定义checkbox.
chkSelected = DataGrid1.Items(i).FindControl("")
chkSelected1 = DataGrid1.Items(i).FindControl("这里是在墨板列中的checkbox的id")
guoyan19811021 2003-08-22
  • 打赏
  • 举报
回复
Dim chkSelected
Dim chkSelected1
什么意思?
gong1 2003-08-21
  • 打赏
  • 举报
回复
up
zhaoliangpat 2003-08-21
  • 打赏
  • 举报
回复
放在那个实践里呢!! 没明白!
guoyan19811021 2003-08-21
  • 打赏
  • 举报
回复
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
hj7680 2003-08-21
  • 打赏
  • 举报
回复
对了,你要先试试你的单选按钮运行是否正常,是不是可以选择唯一的一个。我遇到过这样的问题使用<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事件中
acewang 2003-08-20
  • 打赏
  • 举报
回复
((checkbox)datagrid1.items.findcontrol("checkbox1")).text
wacle 2003-08-20
  • 打赏
  • 举报
回复
foreach(datagriditem item in dgrd.items)
{
checkbox chk=(checkbox)item.findcontrol("chk1");
}
wacle 2003-08-20
  • 打赏
  • 举报
回复
对vb不熟悉,具体的语法你自己去查查
Foreach DataGridItem item In datagrid.Items
CheckBox chk=CType(item.FindControl("chk1"),CheckBox)
End
zhaoliangpat 2003-08-20
  • 打赏
  • 举报
回复
我没看明白 能否给我解释下呢!!
seesea125 2003-08-20
  • 打赏
  • 举报
回复
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);

}

}
seesea125 2003-08-20
  • 打赏
  • 举报
回复
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);

}

}
加载更多回复(1)

62,046

社区成员

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

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

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

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