I have a table (tblUsers) displayed by a GridView with an Edit button, where the Edit button binds the UserId to the URL, so it redirects to that specific user (~../Users/UserEdit.aspx?UserId=25)
Now, tblUsers is connected with tblPayments through UserId so I would like to show a GridView of tblPayments but only those rows for the specific UserId in the URL.
I have successfully created the GridView but I am displaying the whole table for every Id, so I am not sure how to filter it. This is my method so far:
private GridView gvPayments;
protected void Filter(int source)
{
if (HttpContext.Current.User.IsInRole("Administrator"))
{
string PaymentId = string.Empty;
string queryBase = "SELECT * FROM [tblPayments] WHERE PaymentId IS NOT NULL ";
string queryWhere = string.Empty; // if I hardcode where PaymentId=25 it works
string queryOrder = " ORDER BY [PayeeId]";
// FINDCONTROL
sdsPayments.SelectCommand = queryBase + queryWhere + queryOrder;
gvPayments = FormView_Users.Row.FindControl("gvPayments") as GridView;
}
}
I call this method within PageLoad and set it to 0. This is the aspx page, with reduced columns for readability.
<asp:GridView ID="gvPayments" runat="server" AutoGenerateColumns="False" DataKeyNames="PaymentId" DataSourceID="SqlDataSource1" EmptyDataText="There are no data records to display.">
<Columns>
<asp:BoundField DataField="PaymentId" HeaderText="PaymentId" ReadOnly="True" SortExpression="PaymentId" />
</Columns>
</asp:GridView>