2011-08-17 64 views
1

我使用ASP.NET,C#,SQL Server 2005中爲我的項目和 我使用中繼器控制,使得形成是一個網站的會員和旁邊的每個按鈕的用戶的表用戶,以便他們可以添加到你的朋友列表。我有一切設置,除了我不知道如何獲得按鈕單擊後每行的具體信息。我的意思是,按鈕和Repeater控件

如何發送好友請求,以一個人的用戶名顯示除了按鈕?或 如何訪問除了按鈕之外的顯示用戶名,以便我可以將其用於我的代碼?

我的腳本

<asp:Repeater ID="myrepeater" runat="server"> 
     <HeaderTemplate> 
      <table style="font: 8pt verdana"> 
       <tr style="background-color:#3C78C3"> 
        <th>Search Result</th> 
       </tr> 

     </HeaderTemplate> 
     <ItemTemplate> 
      <tr> 
       <td> 
        <%#DataBinder.Eval(Container,"DataItem.allun")%> 
        <asp:Button ID="Button1" runat="server" Text="Button" /> 
       </td> 
      </tr> 
     </ItemTemplate> 
     <FooterTemplate> 
      </table> 
     </FooterTemplate> 

代碼隱藏

protected void btnSearch_Click(object sender, EventArgs e) 
{ 
    con.Open(); 
    if (txtSearch.Text != "") 
    { 
     SqlDataAdapter mycommand = new SqlDataAdapter("select * from WebAdminTable where allun='" + txtSearch.Text + "'", con); 
     DataSet ds = new DataSet(); 
     mycommand.Fill(ds); 
     myrepeater.DataSource = ds; 
     myrepeater.DataBind(); 
    } 
    else 
    { 
     //msgbox for entering value 
    } 
    con.Close(); 
} 

protected void btnAddToMyFList_Click(object sender, EventArgs e) 
{ 
     //?  
} 
+0

另外,如何添加搜索用戶的個人資料照片? –

回答

1

您可以將userName綁定到一個標籤控件,然後你可以的點擊訪問標籤控件的值按鈕像...

protected void btnAddToMyFList_Click(object sender, EventArgs e) 
{ 
    Button btnAddToMyFList = (Button)sender; 
    Label label = (Label)btnAddToMyFList.Parent.FindControl("LabelId"); 
    String labelText = label.Text; //userName of clicked row 
} 
+0

在這一行標籤標記=(標籤)btnAddToMyFList.Parent.FindControl( 「LabelId」);,是什麼( 「LabelId」)? –

+0

你想獲得用戶名?這是分組<%#DataBinder.Eval(容器,「DataItem.allun」)%>? –

+0

好的....謝謝你,先生,我感謝你的幫助。 –