一个gridview里面一列为buttonfield类型  邦定数据库中的一列
如何在点击这个buttonfield的时候获取他的文本  
gridview1.rows[0].cells[0].text
不好用 返回的是创建时的text 负值为空

解决方案 »

  1.   

    ((Button)sender).Text?----------------------------------------------------------------
    很抱歉,没有时间详细解释。通过搜索引擎查找问题及回复的关键词可能会有帮助。
      

  2.   

    sender是gridview吧??请问
    试试:断点看看gridview1.rows[0].cells[0]是否是那要的控件
    ((Button)gridview1.rows[0].cells[0]).text 
      

  3.   

    楼主说的是click的时候获取,难道那时候的sender不是button?----------------------------------------------------------------
    很抱歉,没有时间详细解释。通过搜索引擎查找问题及回复的关键词可能会有帮助。
      

  4.   

    ((Button)gridview1.rows[0].cells[0].FindControl("txtName")).text 
      

  5.   

    1、页面代码:
    <asp:GridView ID="gvw" runat="server" AutoGenerateColumns="False"
                                    Width="100%" CssClass="Grid_Item" DataKeyNames="PublishID" OnRowDataBound="gvw_RowDataBound" AllowPaging="True" >
                                    <Columns>   
                                        <asp:BoundField HeaderText="发布会名称" DataField="PublishName" >
                                            <itemstyle horizontalalign="Left" />
                                            <headerstyle horizontalalign="Center" width="20%" />
                                        </asp:BoundField>
                                        <asp:BoundField HeaderText="工作属性" DataField="WrokAttribute" >
                                            <itemstyle horizontalalign="Center" />
                                            <headerstyle horizontalalign="Center" width="10%" />
                                        </asp:BoundField>
                                        <asp:BoundField HeaderText="发布会日期" DataField="PublishDate" >
                                            <itemstyle horizontalalign="Center" />
                                            <headerstyle horizontalalign="Center" width="10%" />
                                        </asp:BoundField>
                                        <asp:BoundField HeaderText="主题数" DataField="TopicNumber" >
                                            <itemstyle horizontalalign="Center" />
                                            <headerstyle horizontalalign="Center" width="20%" />
                                        </asp:BoundField>     
                                        <asp:BoundField HeaderText="发布方式" DataField="PublishType" >
                                            <itemstyle horizontalalign="Center" />
                                            <headerstyle horizontalalign="Center" width="10%" />
                                        </asp:BoundField>
                                        <asp:TemplateField HeaderText="操作">
                                            <ItemTemplate>
                                                <asp:ImageButton ImageUrl = "../App_Themes/Images/edit.gif" ID="iBtnEdit" runat="server" OnClick="iBtnEdit_Click"/>
                                                <asp:ImageButton ImageUrl = "../App_Themes/Images/bt_icon_del.gif" ID="iBtnDelete" runat ="server" OnClick="iBtnDelete_Click" />
                                                <asp:ImageButton ImageUrl = "../App_Themes/Images/bt_icon_search.gif" ID="iBtnView" runat ="server" OnClick="iBtnView_Click" />
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                    </Columns>
                                    <AlternatingRowStyle CssClass="altertr" />
                                    <RowStyle CssClass="Grid_Item" />
                                    <PagerSettings Visible="False" />
                                </asp:GridView>2、后台代码:
    protected void gvw_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowIndex != -1)
            {
                BLLClass.Sys_Dictionary_Detail bll = new PublicFeelingsNewsPublish.BLL.Sys_Dictionary_Detail();
                //Date
                e.Row.Cells[2].Text = (DateTime.Parse(e.Row.Cells[2].Text)).ToShortDateString();
                //主体数
                e.Row.Cells[1].Text = bll.GetModel(int.Parse(e.Row.Cells[1].Text)).ItemName;
                e.Row.Cells[3].Text = bll.GetModel(int.Parse(e.Row.Cells[3].Text)).ItemName;
                e.Row.Cells[4].Text = bll.GetModel(int.Parse(e.Row.Cells[4].Text)).ItemName;
                //发布方式                ImageButton imageBtnEdit = e.Row.Cells[5].FindControl("iBtnEdit") as ImageButton;
                imageBtnEdit.CommandArgument = gvw.DataKeys[e.Row.RowIndex].Value.ToString(); //e.Row.Cells[0].Text;
                ImageButton imageBtnDelete = e.Row.Cells[5].FindControl("iBtnDelete") as ImageButton;
                imageBtnDelete.CommandArgument = gvw.DataKeys[e.Row.RowIndex].Value.ToString();
                imageBtnDelete.Attributes.Add("onclick", "if( !ConfirmDel()) { return false;} ");
                ImageButton imageBtnView = e.Row.Cells[5].FindControl("iBtnView") as ImageButton;
                imageBtnView.CommandArgument = gvw.DataKeys[e.Row.RowIndex].Value.ToString();
            }
        }    protected void iBtnEdit_Click(object sender, ImageClickEventArgs e)
        {
            _currentID = int.Parse((sender as ImageButton).CommandArgument);
            NewsService.PublishID = _currentID;
            NewsService.NewsType = SysEnum.PublishNewsType.BasicInfo;        Response.Redirect("PublishNewsEditMain.aspx");    }    protected void iBtnDelete_Click(object sender, ImageClickEventArgs e)
        {
            _currentID = int.Parse((sender as ImageButton).CommandArgument);        BLLClass.PublishNews_BasicInfo bll = new PublicFeelingsNewsPublish.BLL.PublishNews_BasicInfo();
            bll.Delete(_currentID);
            _currentID = -1;        Response.Redirect("PublishNewsEditMain.aspx");    }
      

  6.   

    不是这个
    楼上 
    <asp:BoundField HeaderText="发布会名称" DataField="PublishName" > 
                                            <itemstyle horizontalalign="Left" /> 我要的是你这个控件点击的时候 获得这个空间里面的 publishname的值