在运行时更改ButtonField(在Gridview中添加)的ImageURL. [英] Change the ImageURL of ButtonField(added in Gridview) at runtime..

查看:79
本文介绍了在运行时更改ButtonField(在Gridview中添加)的ImageURL.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我在Gridview中添加了一个ButtonField,如..

Hi,

I added a ButtonField in the Gridview like..

<asp:GridView ID="GridView1" runat="server">
    <Columns>
        <asp:ButtonField ButtonType="Image" ImageUrl="ImagePath" />
    </Columns>
    </asp:GridView>




现在,如何在运行时在OnClick事件中更改ButtonField的URL?




Now How can i Change the URL of the ButtonField at runtime in OnClick Event??

推荐答案

<asp:ButtonField ButtonType="Image" ImageUrl="~/Images/pdf.png"  CommandName="pdf_click" ID="imgprint"/>


背后的代码


Code behind

void GridView1_RowCommand(Object sender, GridViewCommandEventArgs e)
 {
 // If multiple buttons are used in a GridView control, use the
 // CommandName property to determine which button was clicked.
 if(e.CommandName=="pdf_click")
  {
   // Convert the row index stored in the CommandArgument
   // property to an Integer.
   int index = Convert.ToInt32(e.CommandArgument);

   // Retrieve the row that contains the button clicked
   // by the user from the Rows collection.
  ButtonField cf = (ButtonField)e.Row.FindControl("imgprint");
  cf.ImageUrl = "images/something.png";
   // Now you have access to the gridviewrow.
  }
}


请参阅此内容,希望对您有所帮助
http://stackoverflow. com/questions/9140930/change-the-imageimage-url-of-buttonfield-which-is-add-in-gridview-by-onclick [ http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.buttonfield.imageurl.aspx [ http://stackoverflow.com/questions/5963806/command-behind-a-gridview-buttonfield [^ ]
Refer this, hope this helps
http://stackoverflow.com/questions/9140930/change-the-imageimage-url-of-buttonfield-which-is-added-in-gridview-by-onclick[^]
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.buttonfield.imageurl.aspx[^]
http://stackoverflow.com/questions/5963806/command-behind-a-gridview-buttonfield[^]


这篇关于在运行时更改ButtonField(在Gridview中添加)的ImageURL.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆