Button获取Repeater一行的两个值
aspx
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<div style=" width:100%;">
<span style=" float:left; width:70%;"><%#Eval("Companyname") %> </span>
<span style=" float:left; width:28%; ">
<asp:Button ID="Button3" runat="server" Text="选择" CommandArgument='<%#Eval("infoID") %>' CommandName='<%#Eval("Companyname") %>'
onclick="Button3_Click" /> </span>
</div>
</ItemTemplate>
</asp:Repeater>
<asp:Label ID="Label1" runat="server" Text=""></asp:Label>
<asp:Label ID="Label2" runat="server" Visible="False"></asp:Label>
cs
protected void Button3_Click(object sender, EventArgs e)
{
Button btn = sender as Button;
// int id = int.Parse(btn.CommandArgument);
string argName = ((Button)sender).CommandName;
string argArg = ((Button)sender).CommandArgument;
Label2.Text = argArg;
Label1.Text = argName;
//DataAccess.Da dac = new DataAccess.Da();
//dac.con.Open();
//string sql = "select * from Company_info where infoID ='" + id + "'";
//SqlCommand cmd = new SqlCommand(sql, dac.con);
//cmd.Connection = dac.con;
//SqlDataReader sdr = cmd.ExecuteReader();
//sdr.Read();
//Label1.Text = sdr["Companyname"].ToString();
//sdr.Close();
//dac.con.Close();
}