gridview有没有办法一点编辑就马上取出当前行某列的值.
(以前用的办法是先点编辑,然后点更新,更新事件里写上
((textbox)this.gridview1.rows[e.rowindex].cells[0].controls[0]).text.tostring()的办法来取, 能不能直接点编辑就可以取出来呢.)

解决方案 »

  1.   

    源视图代码: 
    模板列哦~
    <asp:LinkButton ID="lb" runat="server" CommandName="editrow" Text="编辑" CommandArgument=' <%# Container.DataItemIndex %>'/> 
    cs文件代码: 
    protected void gv_sata_RowCommand(object sender, GridViewCommandEventArgs e) 
        { 
            if (e.CommandName == "editrow") 
            { 
                int iIndex = Convert.ToInt16(e.CommandArgument); 
                GridViewRow gvr = gv_User.Rows[iIndex]; 
                string text = gvr.Cells[0].Text; //根据你要取值的列改索引值哦
            } 
        } 
    这个问题貌似我昨天还回答过。
    新手,互相帮助!
      

  2.   

    if (e.CommandName == "editrow") 
     这句是起什么作用的呢
      

  3.   

    editrow 是代表编辑吗,整句的意思就是  是不是触发了编辑按纽, 是不是这个意思呢.
      

  4.   

    editrow是自己定义的编辑时的commandname,可以这么理解
      

  5.   

    protected void gv_sata_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "editrow")
            {
                int iIndex = Convert.ToInt16(e.CommandArgument);
                GridViewRow gvr = gv_User.Rows[iIndex];
                string text = gvr.Cells[0].Text; //根据你要取值的列改索引值哦
            }
        }
    我照搬以上代码,结果发现点编辑按纽的时候不起作用,我改成如下代码
    protected void gv_sata_RowCommand(object sender, GridViewCommandEventArgs e)
        {
                        int iIndex = Convert.ToInt16(e.CommandArgument);
                GridViewRow gvr = gv_User.Rows[iIndex];
                string text = gvr.Cells[0].Text; //根据你要取值的列改索引值哦
            
        }
    就没有问题,不知道那个IF加上去干嘛用,加上了,反而不灵了.
      

  6.   

    前台如下代码
    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
        {
            this.GridView1.EditIndex = e.NewEditIndex;
            bind();         
        }
      

  7.   

    注意<asp:LinkButton ID="lb" runat="server" CommandName="editrow" Text="编辑" CommandArgument=' <%# Container.DataItemIndex %>'/> 中的CommandName="editrow",这是和我写的那个if语句对应的。因为gridview中可能有好几个LinkButton控件可以触发gv_sata_RowCommand事件,如果没有if语句,这些LinkButton控件触发的事件都是相同的。所以为了区分各个控件的功能,在前台代码中加上CommandName="editrow",后台代码if (e.CommandName == "editrow") ,表示的就是CommandName为editrow的那个控件在gv_sata_RowCommand事件中应运行的代码。不知道我这么说,你能明白不能
      

  8.   

     <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
            BorderStyle="None" Width="100%" onrowdeleting="GridView1_RowDeleting" 
            onrowediting="GridView1_RowEditing" 
            onselectedindexchanging="GridView1_SelectedIndexChanging" 
            BackColor="White" BorderColor="#CCCCCC" BorderWidth="1px" CellPadding="3" 
            DataKeyNames="isosid" onrowupdating="GridView1_RowUpdating" 
            onrowcommand="GridView1_RowCommand">
            <FooterStyle BackColor="White" ForeColor="#000066" />
            <RowStyle ForeColor="#000066" />
            <Columns>
                <asp:BoundField DataField="isosid" HeaderText="ID" />
                <asp:BoundField DataField="规格型号" HeaderText="规格型号" />
                <asp:BoundField DataField="数量" HeaderText="数量" />
                <asp:BoundField DataField="材质颜色" HeaderText="材质颜色" />
                <asp:BoundField DataField="客户型号" HeaderText="客户型号" />
                <asp:BoundField DataField="包装要求" HeaderText="包装要求" />
                <asp:BoundField DataField="连接器类型" HeaderText="连接器类型" />
                <asp:BoundField DataField="完结" HeaderText="完结" />
                <asp:BoundField DataField="完结时间" HeaderText="完结时间" />
                <asp:CommandField ShowEditButton="True" />
                <asp:CommandField ShowSelectButton="True" />
                <asp:CommandField ShowDeleteButton="True" />
            </Columns>
            <PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
            <SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
            <HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
        </asp:GridView>
    以上是我gridview1的代码,问题是gridview1上面明明就有编辑,选择,删除,等三个按纽,为什么在代码上看不到呢
      

  9.   

    <asp:CommandField ShowEditButton="True" /> 
                <asp:CommandField ShowSelectButton="True" /> 
                <asp:CommandField ShowDeleteButton="True" /> 
    这样的话直接row_editing , row_updating事件就可以了,不用row_command了
      

  10.   

    如果用row_editing , row_updating就需要用户点两下了,先点编辑,再点更新,才能获取当前行的值,而现在需要的是直接点编辑获取当前行的值.
      

  11.   

    没搞清你的意思,点编辑获取当前行的值,这个在row_editing中也能做到,你到底是什么需求?
      

  12.   

    楼主将<asp:CommandField ShowEditButton="True" /> 
    <asp:CommandField ShowSelectButton="True" /> 
    <asp:CommandField ShowDeleteButton="True" /> 这3行换成模版列试试。<asp:TemplateField HeaderText="编辑" ShowHeader="False">
    <ItemTemplate>
    <asp:LinkButton ID="lb" runat="server" CommandName="editrow" Text="编辑" CommandArgument=' <%# Container.DataItemIndex %>'/>
    </ItemTemplate>
    </asp:TemplateField>然后后台代码:
    cs文件代码: protected void gv_sata_RowCommand(object sender, GridViewCommandEventArgs e) 
        { 
            if (e.CommandName == "editrow"
            { 
                int iIndex = Convert.ToInt16(e.CommandArgument); 
                GridViewRow gvr = gv_User.Rows[iIndex]; 
                string text = gvr.Cells[0].Text; //根据你要取值的列改索引值哦 
            } 
        } 注意红色部分是对应的。