Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I pass an argument through the OnClick property in an asp.net controller
    primarykey
    data
    text
    <p>Here is my ASP code:</p> <pre><code>&lt;asp:GridView ID="WagerTable" runat="server" AutoGenerateColumns="False" CssClass="basix" &gt; &lt;columns&gt; &lt;asp:BoundField DataField="GameName" HeaderText="Game Name" /&gt; &lt;asp:BoundField DataField="Amount" HeaderText="Amount" /&gt; &lt;asp:BoundField DataField="Comment" HeaderText="Comment" /&gt; &lt;asp:BoundField DataField="CreateTime" HeaderText="Create Time" /&gt; &lt;asp:TemplateField&gt; &lt;ItemTemplate&gt; &lt;asp:LinkButton runat="server" Text="Accept" OnClick="AcceptWager" ID="AcceptButton" /&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;/columns&gt; &lt;/asp:GridView&gt; </code></pre> <p>This is my code behind:</p> <pre><code>protected void Page_Load(object sender, EventArgs e) { AccountManager accManager = new AccountManager(); MembershipUser newUser = Membership.GetUser(HttpContext.Current.User.Identity.Name); Guid UserId = (Guid)newUser.ProviderUserKey; String myConnectionString = ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString; SqlDataReader reader; using (SqlConnection myConnection = new SqlConnection(myConnectionString)) { myConnection.Open(); String selectSql = "SELECT * FROM aspnet_Wagers INNER JOIN aspnet_Games ON aspnet_Wagers.GameId = aspnet_Games.GameId"; SqlCommand myCommand = new SqlCommand(selectSql, myConnection); myCommand.Parameters.AddWithValue("@UserId", UserId); reader = myCommand.ExecuteReader(); WagerTable.DataSource = reader; WagerTable.DataBind(); myConnection.Close(); } } protected void AcceptWager() { } </code></pre> <p>I want to be able to have it so that each LinkButton can pass through an ID from the database as an parameter into the AcceptWager function and then I will do with it from there. The sql column for the ID is WagerId. It is returned in that query that i execute, so it is already in the <code>reader</code>. Thanks</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload