2014-01-28 40 views
0

我有一個鏈接按鈕(鏈接按鈕的文字編輯)在GridView,我給它一個命令名呼叫修改LinkBut​​ton的CommandName的工作不

所以在我設計的代碼是:

<asp:TemplateField> 
     <ItemTemplate> 
      <asp:LinkButton ID="LinkButton1" runat="server" CommandName="modify">Edit</asp:LinkButton> 
      </ItemTemplate> 
    </asp:TemplateField> 

在我後面的代碼是:

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) 
{ 
    LinkButton linkBtn = (LinkButton)sender; 

    if (linkBtn.CommandName == "modify") // tried linkBtn.CommandArguemtn , doesn't help 
    { 
     Panel1.Visible = true; 
     int index = Convert.ToInt32(e.CommandArgument);  

     Label login = (Label)GridView1.Rows[index].Cells[0].FindControl("Label1"); 
     //Things i want to do 

    } 
} 

正如你可以看到我設置面板是可見的,但不會出現...我是在做正確的方法是什麼?我知道使用默認編輯按鈕生成的替代方案,但我不想那樣做。我試圖在gridview中放置一個鏈接按鈕,然後單擊鏈接按鈕,然後應該出現面板(由文本框控件組成),然後在面板中更改gridview數據。

回答

0

只使用

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) 
{ 
    if (e.CommandName == "modify") 
    { 
     Panel1.Visible = true; 
     int index = Convert.ToInt32(e.CommandArgument);  

     Label login = (Label)GridView1.Rows[index].Cells[0].FindControl("Label1"); 
     //Things i want to do 

    } 
} 

你不會需要先檢查一下按鈕,e.CommandName將sufficent

0

嘗試像this.use的CommandName屬性來指定或確定的命令名稱MSDN

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) 
{ 
    if(e.CommandName=="modify") 
     { 
      \\ 
     } 
} 
0

使用以下代碼

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) 
{ 


    if (e.CommandName.ToLower()== "modify") 
    { 
     Panel1.Visible = true; 
     int index = Convert.ToInt32(e.CommandArgument);  

     Label login = (Label)GridView1.Rows[index].Cells[0].FindControl("Label1"); 
     //Things i want to do 

    } 
} 
相關問題