获取buttonfield的文本 一个gridview里面一列为buttonfield类型 邦定数据库中的一列如何在点击这个buttonfield的时候获取他的文本 gridview1.rows[0].cells[0].text不好用 返回的是创建时的text 负值为空 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 ((Button)sender).Text?----------------------------------------------------------------很抱歉,没有时间详细解释。通过搜索引擎查找问题及回复的关键词可能会有帮助。 sender是gridview吧??请问试试:断点看看gridview1.rows[0].cells[0]是否是那要的控件((Button)gridview1.rows[0].cells[0]).text 楼主说的是click的时候获取,难道那时候的sender不是button?----------------------------------------------------------------很抱歉,没有时间详细解释。通过搜索引擎查找问题及回复的关键词可能会有帮助。 ((Button)gridview1.rows[0].cells[0].FindControl("txtName")).text 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"); } 不是这个楼上 <asp:BoundField HeaderText="发布会名称" DataField="PublishName" > <itemstyle horizontalalign="Left" /> 我要的是你这个控件点击的时候 获得这个空间里面的 publishname的值 一条sql查询语句 WEB发布时候,访问不了数据库??? activex控件的使用 求教CSS高手,firefox和IE的打印预览 如何用数据控件在ASP.NET页面显示嵌套数据或特定格式数据?另有相同帖子50分相送 再问datagrid中行上下移动的问题 将DataTable的Data到生成CSV文件里面然后在保存到项目文件夹下面呢 请教,如何实现label类的投影(倒影)但lable中的文字不变 ASP.Net 如何与SQL数据库相连 aspx中如何获取image控件的句柄 Gridview問題.....求助各位高手...急! javascript 定位滚动条的问题
很抱歉,没有时间详细解释。通过搜索引擎查找问题及回复的关键词可能会有帮助。
试试:断点看看gridview1.rows[0].cells[0]是否是那要的控件
((Button)gridview1.rows[0].cells[0]).text
很抱歉,没有时间详细解释。通过搜索引擎查找问题及回复的关键词可能会有帮助。
<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"); }
楼上
<asp:BoundField HeaderText="发布会名称" DataField="PublishName" >
<itemstyle horizontalalign="Left" /> 我要的是你这个控件点击的时候 获得这个空间里面的 publishname的值