c#
  • asp.net
  • gridview
  • itemtemplate
  • 2012-08-03 59 views 0 likes 
    0

    我在我的asp.net項目中有一個gridview,我使用的項目模板像;GridView的項目模板linkbutton趕上後面的代碼

    <asp:TemplateField> 
            <ItemTemplate> 
             <asp:LinkButton ID = "lnkSil" runat="server" CommandName="bla" 
    CommandArgument='<%# ((GridViewRow) Container).RowIndex %>' Text= "Sil" ></asp:LinkButton> 
            </ItemTemplate> 
            </asp:TemplateField> 
    

    我想從後面的代碼中看到這一點,我使用下面的代碼;

    ((Button)e.Row.Cells[1].Controls[0]).Attributes.Add("onclick", "return confirm('Bu kaydi silmek istediginizden emin misiniz?')"); 
    

    ,但我失敗了我如何能趕上落後於這個代碼控制這樣

    還我試圖

    ((LinkButton)e.Row.Cells[1].Controls[0]).Attributes.Add("onclick", "return confirm('Bu kaydi silmek istediginizden emin misiniz?')"); 
    
    +0

    是有一個原因,你不能做到這一點的標記? – codingbiz 2012-08-03 10:23:03

    回答

    0

    ,如果你想獲得訪問事件,而不JavaScript的再使用GridView1_RowCommand。

    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) 
    { 
        int currentRowIndex = Int32.Parse(e.CommandArgument.ToString()); 
        LinkButton bf = (LinkButton)gv.Rows[currentRowIndex].Cells[1].Controls[0]; 
        ... 
    } 
    
    0

    試試這個..

    protected void gvMyGrid_RowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e) 
    { 
    if (e.Row.RowType == DataControlRowType.DataRow) { 
    LinkButton lnkSil = (LinkButton)e.Row.FindControl("lnkSil"); 
    lnkSil.Attributes.Add("onclick", "javascript:return confirm('Bu kaydi silmek istediginizden emin misiniz?');"); 
        } 
    } 
    
    相關問題