Record is not showing in GridView.
<asp:GridView ID="GridView2" runat="server" DataKeyNames="AdmissionNo" OnRowDataBound="OnRowDataBound" CssClass="table table-striped table-bordered table-hover">
</asp:GridView>
private static DataTable GetData(string query)
{
string strConnString = ConfigurationManager.ConnectionStrings["ConStr"].ConnectionString;
using (SqlConnection con = new SqlConnection(strConnString))
{
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandText = query;
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
using (DataSet ds = new DataSet())
{
DataTable dt = new DataTable();
sda.Fill(dt);
return dt;
}
}
}
}
}
protected void OnRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string Id = GridView2.DataKeys[e.Row.RowIndex].Value.ToString();
GridView2.DataSource = GetData(string.Format("select fc.AdmissionNo,NetBal,Paid,RemBal,FeesMonth from tblFeesCollection as fc inner join tblStdReg as sr on fc.AdmissionNo=sr.AdmissionNo where sr.ClassID='55' and RemBal > 0 and FeeID IN (SELECT MAX(FeeID) FROM tblFeesCollection where fc.AdmissionNo= '{0}')", Id));
GridView2.DataBind();
}
}
and data is here
AdmissionNo
|
Month
|
Recievable
|
NetBal
|
Paid
|
RemBal
|
R-01
|
Jan
|
1000
|
1000
|
600
|
400
|
R-01
|
Jan
|
1000
|
400
|
200
|
100
|
R-02
|
Jan
|
1000
|
1000
|
400
|
600
|
R-02
|
Jan
|
1000
|
600
|
300
|
300
|
R-02
|
Jan
|
1000
|
300
|
200
|
100
|
R-03
|
Jan
|
1000
|
1000
|
500
|
500
|
R-03
|
Jan
|
1000
|
500
|
200
|
300
|
R-03
|
Jan
|
1000
|
300
|
150
|
150
|
R-04
|
Jan
|
1000
|
1000
|
700
|
300
|
R-05
|
Jan
|
1000
|
1000
|
800
|
200
|