這裏通過單擊屬性我如何傳遞一個參數是我的ASP代碼:在一個asp.net控制器
<asp:GridView ID="WagerTable" runat="server" AutoGenerateColumns="False" CssClass="basix" >
<columns>
<asp:BoundField DataField="GameName" HeaderText="Game Name" />
<asp:BoundField DataField="Amount" HeaderText="Amount" />
<asp:BoundField DataField="Comment" HeaderText="Comment" />
<asp:BoundField DataField="CreateTime" HeaderText="Create Time" />
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton runat="server" Text="Accept" OnClick="AcceptWager" ID="AcceptButton" />
</ItemTemplate>
</asp:TemplateField>
</columns>
</asp:GridView>
這是我的代碼背後:
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()
{
}
我希望能夠爲了讓每個LinkButton都可以通過數據庫中的ID作爲參數傳遞給AcceptWager函數,然後我將使用它。 ID的sql列是WagerId。它在我執行的查詢中返回,所以它已經在reader
中。謝謝
說法是拼寫錯誤 – 2016-11-17 16:29:55
感謝@nueverest – Hogan 2016-11-17 16:38:43