首页 新闻 论坛 群组 Blog 文档 下载 读书 Tag 网摘 搜索 .NET Java 游戏 视频 人才 外包 培训 数据库 书店 程序员
中国软件网
欢迎您:游客 | 登录 注册 帮助
  • GridView嵌套的问题 [已结帖,结帖人:Lisen_1987]
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • Lisen_1987
    • 等级:
    • 可用分等级:
    • 总技术分:
    • 总技术分排名:
    • 结帖率:
    发表于:2008-11-06 21:46:59 楼主
    两个GridView嵌套,嵌套的GridView有编辑和删除两个按钮,外围的GridView也有两个按钮,我想实现的是当按下嵌套的GridView的编辑按钮时,这个GridView就变成编辑状态,而外围的GridView没有变化,同理外围的GridView的也一样不会影响到嵌套的GridView,请教一下要怎么实现,我在网上找了很久都没有找到相关的答复,拜托哪位高手帮忙解决一下,谢谢啦
    150  修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • qq283617300
    • 等级:
    • 可用分等级:
    • 总技术分:
    • 总技术分排名:
    发表于:2008-11-06 21:53:451楼 得分:5
    顶下~ 我还是没弄出来! 你找到答案了 给我发一个哈!我的qq邮箱! 谢谢了~
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • koukoujiayi
    • 等级:
    • 可用分等级:
    • 总技术分:
    • 总技术分排名:
    发表于:2008-11-06 21:55:022楼 得分:5
    我也做够GridView嵌套,按删除是不会有变化的,按编辑只能再读一遍!!!
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • kfps8kfps8
    • 等级:
    • 可用分等级:
    • 总技术分:
    • 总技术分排名:
    发表于:2008-11-06 21:56:343楼 得分:5
    没弄过,帮顶!
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • magicbacon
    • 等级:
    • 可用分等级:
    • 总技术分:
    • 总技术分排名:
    发表于:2008-11-06 21:59:164楼 得分:5
    能看看代码吗,还没看过是怎么嵌套的~
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • magicbacon
    • 等级:
    • 可用分等级:
    • 总技术分:
    • 总技术分排名:
    发表于:2008-11-06 22:00:065楼 得分:0
    能看看代码吗,还没看过是怎么嵌套的~
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • y_qingbin
    • 等级:
    • 可用分等级:
    • 总技术分:
    • 总技术分排名:
    发表于:2008-11-06 22:01:466楼 得分:0
    我也想看看,呵呵
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • lfzpf
    • 等级:
    • 可用分等级:
    • 总技术分:
    • 总技术分排名:
    发表于:2008-11-06 22:21:087楼 得分:5
    HTML code
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" CellPadding="4" ForeColor="#333333" GridLines="None" Height="322px" Width="613px" DataKeyNames="id" Font-Size="12px" OnRowCancelingEdit="GridView1_RowCancelingEdit" OnRowEditing="GridView1_RowEditing" OnRowUpdating="GridView1_RowUpdating" OnRowDeleting="GridView1_RowDeleting" OnDataBound="GridView1_DataBound" OnRowDataBound="GridView1_RowDataBound"> <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /> <RowStyle BackColor="#F7F6F3" ForeColor="#333333" /> <EditRowStyle BackColor="#999999" /> <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" /> <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" /> <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /> <AlternatingRowStyle BackColor="White" ForeColor="#284775" /> <Columns> <asp:CommandField ShowSelectButton="true"/> <asp:CommandField ShowEditButton="True"/> <asp:CommandField ShowDeleteButton="True" DeleteText="&lt;div id=&quot;delete&quot; onclick=&quot;javascript:return confirm('你确认删除吗?')&quot;&gt;删除&lt;/div&gt;"/> <asp:BoundField DataField="id" HeaderText="项目编号" ReadOnly="True"/> <asp:TemplateField HeaderText="投票项目"> <ItemTemplate> <asp:Label runat="server" id="lblVoteTitle" Text='<%#Bind("voteTitle")%>'></asp:Label> </ItemTemplate> <EditItemTemplate> <asp:TextBox runat="server" id="txtVoteTitle" Text='<%#Bind("voteTitle")%>'></asp:TextBox> </EditItemTemplate> </asp:TemplateField> <asp:BoundField DataField="voteSum" HeaderText="投票总数" ReadOnly="True"/> <asp:TemplateField HeaderText="项目明细"> <ItemTemplate> <asp:GridView runat="server" ID="GridView2" AutoGenerateColumns="false" OnRowCancelingEdit="GridView2_RowCancelingEdit" OnRowEditing="GridView2_RowEditing" DataKeyNames="voteDetailsID" OnRowDeleting="GridView2_RowDeleting" OnRowUpdating="GridView2_RowUpdating"> <Columns> <asp:CommandField ShowEditButton="true" ControlStyle-Width="40"/> <asp:CommandField ShowDeleteButton="true" /> <asp:BoundField DataField="voteDetailsID" HeaderText="选项编号" ReadOnly="true"/> <asp:TemplateField HeaderText="选项名称"> <ItemTemplate> <asp:Label runat="server" ID="lblVoteItem" Text='<%#Bind("voteItem") %>'></asp:Label> </ItemTemplate> <EditItemTemplate> <asp:TextBox runat="server" ID="txtVoteItem" Text='<%#Bind("voteItem") %>'></asp:TextBox> </EditItemTemplate> </asp:TemplateField> <asp:BoundField DataField="voteNum" HeaderText="选项票数" ReadOnly="true"/> </Columns> </asp:GridView> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> <asp:Panel runat="server" ID="panel1" Height="42px" Width="289px" Font-Size="12px"> <asp:Button runat="server" ID="btnFirst" Text="首页" CommandName="first" OnClick="btnFirst_Click"/> <asp:Button runat="server" ID="btnLast" Text="尾页" CommandName="last" OnClick="btnLast_Click"/> <asp:Button runat="server" ID="btnPre" Text="上一页" CommandName="pre" OnClick="btnPre_Click" /> <asp:Button runat="server" ID="btnNext" Text="下一页" CommandName="next" OnClick="btnNext_Click"/> </asp:Panel>

    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • lfzpf
    • 等级:
    • 可用分等级:
    • 总技术分:
    • 总技术分排名:
    发表于:2008-11-06 22:21:538楼 得分:0
    C# code
    public partial class toupiao : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { dataBind(); } } void dataBind() { db mydb = new db(); string strSql = "select * from voteMaster"; DataSet ds = mydb.getDs(strSql); this.GridView1.AllowPaging = true; this.GridView1.PageSize = 5; this.GridView1.DataSource = ds.Tables["admin"].DefaultView; this.GridView1.DataBind(); if (this.GridView1.PageIndex == 0) { this.btnPre.Enabled = false; this.btnFirst.Enabled = false; } else { this.btnPre.Enabled = true; this.btnFirst.Enabled = true; } if (this.GridView1.PageIndex == this.GridView1.PageCount - 1) { this.btnNext.Enabled = false; this.btnLast.Enabled = false; } else { this.btnLast.Enabled = true; this.btnNext.Enabled = true; } } protected void btnFirst_Click(object sender, EventArgs e) { this.GridView1.PageIndex = 0; dataBind(); } protected void btnLast_Click(object sender, EventArgs e) { this.GridView1.PageIndex = this.GridView1.PageCount - 1; dataBind(); } protected void btnPre_Click(object sender, EventArgs e) { this.GridView1.PageIndex = Math.Max(this.GridView1.PageIndex - 1, 0); dataBind(); } protected void btnNext_Click(object sender, EventArgs e) { this.GridView1.PageIndex = Math.Min(this.GridView1.PageIndex + 1, this.GridView1.PageCount - 1); dataBind(); } protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e) { this.GridView1.EditIndex = e.NewEditIndex; dataBind(); } protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e) { this.GridView1.EditIndex = -1; dataBind(); } protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e) { int id = Convert.ToInt32(this.GridView1.DataKeys[e.RowIndex]["id"].ToString()); string voteTitle = ((TextBox)this.GridView1.Rows[e.RowIndex].Cells[3].FindControl("txtVoteTitle")).Text.ToString(); string strSql = "update voteMaster set voteTitle = '" + voteTitle + "' where id='" + id + "'"; db mydb = new db(); int row = mydb.executeNonquery(strSql); if (row == 1) { Response.Write("<script language='javascript'>alert('数据更新成功!')</script>"); this.GridView1.EditIndex = -1; dataBind(); } else Response.Write("<script language='javascript'>alert('数据更新失败!')</script>"); } protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) { int id = Convert.ToInt32(this.GridView1.DataKeys[e.RowIndex]["id"].ToString()); string strSql = "delete from voteMaster where id ='" + id + "'"; db mydb = new db(); mydb.executeNonquery(strSql); string sql = "delete from voteDetails where id = '" + id + "'"; mydb.executeNonquery(strSql); dataBind(); } protected void GridView2_RowEditing(object sender, GridViewEditEventArgs e) { GridView GridView2 = sender as GridView; GridView2.EditIndex = e.NewEditIndex; dataBind(); } protected void GridView2_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e) { GridView GridView2 = sender as GridView; GridView2.EditIndex = -1; dataBind(); } protected void GridView2_RowDeleting(object sender, GridViewDeleteEventArgs e) { GridView GridView2 = sender as GridView; int id = Convert.ToInt32(GridView2.DataKeys[e.RowIndex]["voteDetailsID"].ToString()); string strSql = "delete from voteDetails where voteDetailsID='" + id + "'"; db mydb = new db(); mydb.executeNonquery(strSql); dataBind(); } protected void GridView1_DataBound(object sender, EventArgs e) { } protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { GridView GridView2 = (GridView)e.Row.FindControl("GridView2"); if (GridView2 != null) { int id = Convert.ToInt32(this.GridView1.DataKeys[e.Row.RowIndex]["id"].ToString()); string strSql = "select voteDetailsID,voteItem,voteNum from voteDetails where id ='" + id + "'"; db mydb = new db(); DataSet ds = mydb.getDs(strSql); GridView2.DataSource = ds.Tables[0].DefaultView; GridView2.DataBind(); } } } protected void GridView2_RowUpdating(object sender, GridViewUpdateEventArgs e) { GridView GridView2 = sender as GridView; int id = Convert.ToInt32(GridView2.DataKeys[e.RowIndex]["voteDetailsID"].ToString()); string voteItem = ((TextBox)GridView2.Rows[e.RowIndex].Cells[3].FindControl ("txtVoteItem")).Text.ToString(); string strSql = "update voteDetails set voteItem='" + voteItem + "' where voteDetailsID ='" + id + "'"; db mydb = new db(); mydb.executeNonquery(strSql); dataBind(); } }
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • Lisen_1987
    • 等级:
    • 可用分等级:
    • 总技术分:
    • 总技术分排名:
    发表于:2008-11-06 22:32:519楼 得分:0
    to lfzpf
      你的方法我试了,不行,按了之后没反应啊


    下面是我的前台代码,其实我没试过GridView嵌套,这次用实在是没什么办法
    HTML code
    <asp:GridView id="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="tq_id" OnRowCommand="GridView1_RowCommand" OnRowDataBound="GridView1_RowDataBound" OnRowCancelingEdit="GridView1_RowCancelingEdit" OnRowDeleting="GridView1_RowDeleting" OnRowEditing="GridView1_RowEditing" OnRowUpdating="GridView1_RowUpdating" ShowHeader="False"> <Columns> <asp:TemplateField><EditItemTemplate> <asp:Label id="Label1" runat="server" Text='<%# Bind("u_name")%>' Width="136px" __designer:wfdid="w21"></asp:Label> <asp:Label id="Label2" runat="server" Text='<%# Bind("tq_date") %>' Width="223px" __designer:wfdid="w22"></asp:Label> <asp:TextBox id="TextBox2" runat="server" Text='<%# Bind("tq_content")%>' Width="360px" TextMode="MultiLine" Height="74px" __designer:wfdid="w23"></asp:TextBox> <asp:GridView id="GridView3" runat="server" AutoGenerateColumns="False" Width="295px" __designer:wfdid="w24"> <Columns> <asp:TemplateField> <EditItemTemplate> <asp:TextBox id="TextBox1" runat="server" Width="430px" TextMode="MultiLine" Height="80px" ></asp:TextBox> </EditItemTemplate> <ItemTemplate> <asp:Label id="Label1" runat="server" Width="319px" Height="80px" ></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:CommandField ShowEditButton="True"></asp:CommandField> <asp:CommandField ShowDeleteButton="True"></asp:CommandField> </Columns> </asp:GridView> <asp:Button id="Button1" runat="server" Text="回复" CommandArgument='<%# Eval("tq_id") %>'></asp:Button> <asp:Panel id="Panel1" runat="server" Width="306px" Height="151px" Visible="false"> <asp:TextBox id="TextBox3" runat="server" Width="301px" TextMode="MultiLine" Height="105px"></asp:TextBox> <asp:LinkButton id="LinkButton1" runat="server" Text="提交" CommandArgument='<%# Eval("tq_id") %>' OnCommand="LinkButton1_Command"></asp:LinkButton> </asp:Panel> </EditItemTemplate> <ItemTemplate> <asp:Label id="Label1" runat="server" Text='<%# Bind("u_name")%>' Width="136px" __designer:wfdid="w13"></asp:Label> <asp:Label id="Label2" runat="server" Text='<%# Bind("tq_date") %>' Width="216px" __designer:wfdid="w14"></asp:Label> <asp:Label id="Label3" runat="server" Text='<%# Bind("tq_content") %>' Width="360px" Height="74px" __designer:wfdid="w15"></asp:Label> <asp:GridView id="GridView2" runat="server" DataKeyNames="tq_id" AutoGenerateColumns="False" Width="358px" __designer:wfdid="w16" DataSource='<%#((System.Data.DataRowView)Container.DataItem).CreateChildView("child") %>' ShowHeader="False" OnRowEditing="GridView2_RowEditing" OnRowCancelingEdit="GridView2_RowCancelingEdit" OnRowUpdating="GridView2_RowUpdating" OnRowDeleting="GridView2_RowDeleting"> <Columns> <asp:TemplateField> <EditItemTemplate> <asp:TextBox id="TextBox1" runat="server" Width="430px" TextMode="MultiLine" Height="80px" Text='<%# Bind("tr_content") %>'></asp:TextBox> </EditItemTemplate> <ItemTemplate> <asp:Label id="Label1" runat="server" Width="319px" Height="80px" Text='<%# Bind("tr_content") %>' ></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:CommandField ShowEditButton="True"></asp:CommandField> <asp:CommandField ShowDeleteButton="True"></asp:CommandField> </Columns> </asp:GridView> <asp:Button id="Button1" runat="server" Text="回复" __designer:wfdid="w17" CommandArgument='<%# Eval("tq_id") %>'></asp:Button> <asp:Panel id="Panel1" runat="server" Width="306px" Height="151px" __designer:wfdid="w18" Visible="false"> <asp:TextBox id="TextBox3" runat="server" Width="301px" TextMode="MultiLine" Height="105px" __designer:wfdid="w19"></asp:TextBox> <asp:LinkButton id="LinkButton1" runat="server" Text="提交" __designer:wfdid="w20" CommandArgument='<%# Eval("tq_id") %>' OnCommand="LinkButton1_Command"></asp:LinkButton> </asp:Panel> </ItemTemplate> </asp:TemplateField> <asp:CommandField ShowEditButton="True"></asp:CommandField> <asp:CommandField ShowDeleteButton="True"></asp:CommandField> </Columns> </asp:GridView>
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • wjxluck
    • 等级:
    • 可用分等级:
    • 总技术分:
    • 总技术分排名:
    发表于:2008-11-06 23:10:2410楼 得分:0
    up
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • Lisen_1987
    • 等级:
    • 可用分等级:
    • 总技术分:
    • 总技术分排名:
    发表于:2008-11-06 23:23:1111楼 得分:0
    我这么问,不知道有没有人知道是怎么回事呢?
    比如在GridView1_RowEditing这个事件里,能够获得GridView1这个ID,但是在GridView2_RowEditing这个事件里却获取不到GridView2这个ID,因为GridView2是嵌套在GridView1的模板列里面,我现在就是在这里卡住了,不知道要怎么解决
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • phper2008
    • 等级:
    • 可用分等级:
    • 总技术分: