2012-11-13 56 views
0

我有我的網頁上和標籤控件存在,在標籤控件存在也存在在GridView一個gridview.The值下方的標籤控制的rowIndex。該標籤控件具有這樣得到的GridView的基礎上,標籤控制值

3244|Yellow Ink| Test Link 

在GridView價值,我有一個價值3244太

3244 yello Ink Test Link 
3255 Green Link Test2 

我想要的3244行索引在我的代碼,一旦頁面加載後面。他們是否有辦法做到這一點。

任何幫助將不勝感激。

+0

你解決了這個問題嗎? –

回答

0

不知道你有什麼類型的數據源,這樣做將與LINQ這樣的一種方法:

protected void Page_Load(object sender, EventArgs e) 
{ 
    // Fetch the text from your label. (I'm assuming that you have only one label with the text "3244|Yellow Ink| Test Link". 
    string text = Label1.Text; 

    // Find the first row or return null if not found. 
    var resultRow = GridView1.Rows.Cast<GridViewRow>().FirstOrDefault(row => 
    { 
     // Get the id (that I'm guessing is the first (0-index) column/cell) 
     var id = row.Cells[0].Text; 

     // Return true/false if the label text starts with the same id. 
     return text.StartsWith(id); 
    }); 

    if (resultRow != null) 
    { 
     var index = resultRow.RowIndex; 
    } 
} 

一個較短的版本是這樣的:

var resultRow = GridView1.Rows.Cast<GridViewRow>() 
    .FirstOrDefault(r => text.StartsWith(r.Cells[0].Text)); 
0
protected void btnJobAppSelected_Click(object sender, EventArgs e) 
{ 
    foreach (GridViewRow row in GridViewJobApplications.Rows) 
    { 

     int rowIndex = ((sender as LinkButton).NamingContainer as GridViewRow).RowIndex; 

     LinkButton btnJobAppSelected = (LinkButton)GridViewJobApplications.Rows[rowIndex].FindControl("btnJobAppSelected"); 

    } 
}