/// <summary>
        /// 生成事件时激发
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void DVClientInfo_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            //int strProjectId = Convert.ToInt32(e.Item.Cells[0].Text);
            int strProjectId = 0;            GridViewRow gvrow = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer);
            int index = gvrow.RowIndex;
            string id = DVClientInfo.Rows[index].Cells[1].Text.ToString();            if (e.CommandName == "redact")//编辑
            { 
            }
            else if (e.CommandName == "forbid")//禁用
            {
                bool temp = centaline.Pro.ClassLibrary.Property.CProject.UpStatusF(strProjectId);
            }
            else if (e.CommandName == "comeback")//恢复
            {
                bool temp = centaline.Pro.ClassLibrary.Property.CProject.UpStatusR(strProjectId);
            }
        }
<asp:GridView ID="DVClientInfo" runat="server"onrowdatabound="DVClientInfo_RowDataBound" onrowcommand="DVClientInfo_RowCommand">
                            <Columns>
                                <asp:TemplateField>
                                <HeaderTemplate>
                                  <input id="Checkbox2" type="checkbox" runat="server" /><label>全选</label>
                                </HeaderTemplate>
                                <Headerstyle ForeColor="#333333" Height="24px" Width="60Px" Wrap="False" />
                                <Itemstyle HorizontalAlign="Center" Height="24px" />
                              </asp:TemplateField>
                                <asp:BoundField Visible="False" DataField="ProjectId" HeaderText="ProjectId">
                                </asp:BoundField>
                                <asp:BoundField DataField="ProjectName" HeaderText="项目名称" >
                                </asp:BoundField>
                                <asp:BoundField DataField="ProjectCode" HeaderText="项目编号" >
                                </asp:BoundField>
                                <asp:BoundField DataField="orgName" HeaderText="隶属部门" >
                                </asp:BoundField>
                                <asp:BoundField DataField="Status" HeaderText="状态" >
                                </asp:BoundField>
                                <asp:TemplateField HeaderText="操作">
                                    <ItemTemplate>
                                        <asp:LinkButton ID="lbtn_redact" runat="server" CommandName="redact" ForeColor="#0099FF">编辑</asp:LinkButton>
                                        <asp:LinkButton ID="lbtn_forbid" runat="server" CommandName="forbid" ForeColor="#0099FF">禁用</asp:LinkButton>
                                        <asp:LinkButton ID="lbtn_comeback" runat="server" CommandName="comeback" ForeColor="#0099FF">恢复</asp:LinkButton>
                                    </ItemTemplate>
                                    <Itemstyle HorizontalAlign="Center" />
                                </asp:TemplateField>
                            </Columns>
                        </asp:GridView>
我要把<asp:BoundField Visible="False" DataField="ProjectId" HeaderText="ProjectId"></asp:BoundField>中的Visible="False"去掉后台id才能取到值!可是这个列又不能显示出来!高手能帮忙解决一下吗?

解决方案 »

  1.   


    <asp:HiddenField ID="HiddenFieldId" runat="server" Value='<%# Eval("ProjectId") %>' />用隐藏域存ProjectId,取的时候从隐藏域里面取就可以了
      

  2.   

    http://topic.csdn.net/u/20100115/15/d4c41926-9e50-4fe7-8030-96d0d59b01b9.html
    这里不是有答案了?
      

  3.   

    如果用RowCommand,可以这样取ProjectIdif (null != e.CommandArgument)
    {
        int ProjectId = Convert.ToInt32(e.CommandArgument);
    }
      

  4.   


    是啊
      你隐藏ID列
      也可以从上次的方法获取啊
    你上次用的我第一个方法
    直接gridview.rows.cell
     我不是还有另外一种 
    获取隐藏列的方法也发给你了么
      

  5.   


    <asp:HiddenField ID="ooxx" runat="server" Value='<%# Eval("ProjectId") %>' />
                                    </asp:HiddenField> 你确定GridView  里面有这个属性?
      

  6.   


                GridViewRow gvrow = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer);
                int index = gvrow.RowIndex;
                //string id = DVClientInfo.Rows[index].Cells[1].Text.ToString();
                string tNumber = DVClientInfo.DataKeys[index].Values["ProjectId"].ToString();index 会数组溢出?
      

  7.   

    不是index的问题
    是你ProjectId 没有存放在datakeys中吧
      

  8.   

    应该是这个问题。。只要Gridview没错,应该不会溢出啊!
      

  9.   

    前台绑定参数CommandArgument;<asp:LinkButton ID="lbtn_redact" runat="server" CommandName="redact" CommandArgument='<%# Bind("id") %>' ForeColor="#0099FF">编辑</asp:LinkButton>
    后台取值if (e.CommandName == "redact")//编辑

       e.CommandArgument = "取值"
    }
      

  10.   


    在左边工具栏 -->“标准”栏里面,你找找,拖进去设置一下就行了,和Gridview没关系
      

  11.   

    <asp:GridView ID="DVClientInfo" runat="server" DataKeyNames="Grup"这样?
      

  12.   

    你查数据的时候,ProjectId查出来了吗?
    要不你把你查询数据的代码发出来看看
      

  13.   

    gridview属性栏有个DataKeys 
    输入ProjectId 就OK
    或者在源码中
    <asp:GridView ID="GridView1" runat="server" DataKeyNames="ProjectId">
                        </asp:GridView>
      

  14.   

    当我把 Visible="False" 去掉就可以查出来/// <summary>
            /// 生成事件时激发
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            protected void DVClientInfo_RowCommand(object sender, GridViewCommandEventArgs e)
            {
                //int strProjectId = Convert.ToInt32(e.Item.Cells[0].Text);
                int strProjectId = 0;            GridViewRow gvrow = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer);
                int index = gvrow.RowIndex;
                string id = DVClientInfo.Rows[index].Cells[1].Text.ToString();
                if (e.CommandName == "redact")//编辑
                {             }
                else if (e.CommandName == "forbid")//禁用
                {
                    bool temp = centaline.Pro.ClassLibrary.Property.CProject.UpStatusF(strProjectId);
                }
                else if (e.CommandName == "comeback")//恢复
                {
                    bool temp = centaline.Pro.ClassLibrary.Property.CProject.UpStatusR(strProjectId);
                }
            }
      

  15.   


     datakeys 属性加哪里呀?怎么加呀?
      

  16.   

    不用Visible="False" 你别往GridView里面邦这一列不就不显示projectId了吗
      

  17.   


    <asp:GridView ID="DVClientInfo" runat="server"onrowdatabound="DVClientInfo_RowDataBound" onrowcommand="DVClientInfo_RowCommand">
                                <Columns>
                                    <asp:TemplateField>
                                    <HeaderTemplate>
                                      <input id="Checkbox2" type="checkbox" runat="server" /><label>全选</label>
                                    </HeaderTemplate>
                                    <Headerstyle ForeColor="#333333" Height="24px" Width="60Px" Wrap="False" />
                                    <Itemstyle HorizontalAlign="Center" Height="24px" />
                                  </asp:TemplateField>
                                    <asp:BoundField DataField="ProjectName" HeaderText="项目名称" >
                                    </asp:BoundField>
                                    <asp:BoundField DataField="ProjectCode" HeaderText="项目编号" >
                                    </asp:BoundField>
                                    <asp:BoundField DataField="orgName" HeaderText="隶属部门" >
                                    </asp:BoundField>
                                    <asp:BoundField DataField="Status" HeaderText="状态" >
                                    </asp:BoundField>
                                    <asp:TemplateField HeaderText="操作">
                                        <ItemTemplate>
                                            <asp:LinkButton ID="lbtn_redact" runat="server" CommandName="redact" ForeColor="#0099FF">编辑</asp:LinkButton>
                                            <asp:LinkButton ID="lbtn_forbid" runat="server" CommandName="forbid" ForeColor="#0099FF">禁用</asp:LinkButton>
                                            <asp:LinkButton ID="lbtn_comeback" runat="server" CommandName="comeback" ForeColor="#0099FF">恢复</asp:LinkButton>
                                        </ItemTemplate>
                                        <Itemstyle HorizontalAlign="Center" />
                                    </asp:TemplateField>
                                </Columns>
                            </asp:GridView>
    这样行了,不要projectId,你绑它干嘛
      

  18.   


    绑他有用!呵呵!所用处理都要用到projectId!
      

  19.   

    HTML code
    <asp:HiddenField ID="HiddenFieldId" runat="server" Value='<%# Eval("ProjectId") %>' />
    用隐藏域存ProjectId,取的时候从隐藏域里面取就可以了