Add the key as a
data-
attribute on your button:
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="btnpopup" runat="server"
Text="LoadBugs" CssClass="popUp"
data-activity-id='<%# Eval("IdActivity") %>' />
</ItemTemplate>
</asp:TemplateField>
You can then retrieve the ID from your Javascript, and pass it to the server:
$(document).ready(function () {
$(".popUp").click(function () {
var activityId = $(this).data("activityId");
$("#bug").empty();
$("#divModal").dialog({
...
open: LoadData(activityId)
});
return false;
});
});
function LoadData(activityId) {
$.ajax({
...
data: JSON.stringify({ activityId: activityId }),
...
});
}
And then use the ID on the server to filter the list:
[WebMethod]
public static BugDetails[] GetBugs(int activityId)
{
using (MySqlConnection conn = new MySqlConnection(WebConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString))
using (MySqlCommand cmd = new MySqlCommand("select * from bugs where IdActivity = @ActivityId" , conn))
{
cmd.Parameters.AddWithValue("@ActivityId", activityId);
DataTable dt = new DataTable();
MySqlDataAdapter adp = new MySqlDataAdapter(cmd);
adp.Fill(dt);
List<BugDetails> bugs = new List<BugDetails>(dt.Rows.Count);
foreach(DataRow dtrow in dt.Rows)
{
bugs.Add(new BugDetails
{
IdBug = dtrow["IdBug"].ToString(),
Bug = dtrow["Bug"].ToString(),
Status = dtrow["Status"].ToString(),
});
}
return bugs.ToArray();
}
}