Hi, folks. I'm new to C# and the .NET framework, so if I've made a stupid mistake that's causing this problem please forgive and bear with me.
I have a simple query that I'm trying to output in a datagrid. The query is executing correctly, the correct number of results is displayed, and the datagrid is indeed generated -- it's just not being filled with the data.
Here's the code for the datagrid in the .aspx file:
And here's the section of the C# code that is filling (or not filling) the datagrid (not that string strSQL is ommitted to save space):
The grid is output, there are four rows with five cells in each row, but there is no data in the cell. I know the data is being returned as I output the number of records returned in the lblError label.
Can anyone give me an idea as to where I've gone wrong here? I'm assuming it's something small that I'm missing, but I've looked through a plethora of tutorials and guides on this and can't see what I'm overlooking.
Thanks very much in advance.
Cheers,
Pablo
I have a simple query that I'm trying to output in a datagrid. The query is executing correctly, the correct number of results is displayed, and the datagrid is indeed generated -- it's just not being filled with the data.
Here's the code for the datagrid in the .aspx file:
Code:
<asp:datagrid id="dgSearchResults" runat="server" AutoGenerateColumns="False" CellPadding="4"
GridLines="Horizontal" ShowHeader="False" Width="98%" BorderStyle="Dashed">
<AlternatingItemStyle BorderWidth="1px" BorderStyle="Solid" BorderColor="Transparent" BackColor="#EEEEEE"></AlternatingItemStyle>
<Columns>
<asp:BoundColumn HeaderText="Grant Description">
<HeaderStyle Width="35%"></HeaderStyle>
</asp:BoundColumn>
<asp:BoundColumn HeaderText="Granting Agency">
<HeaderStyle Width="35%"></HeaderStyle>
</asp:BoundColumn>
<asp:BoundColumn HeaderText="Principle Investigator">
<HeaderStyle Width="20%"></HeaderStyle>
</asp:BoundColumn>
<asp:BoundColumn HeaderText="Additional Researchers">
<HeaderStyle Width="5%"></HeaderStyle>
</asp:BoundColumn>
<asp:BoundColumn HeaderText="Grant Amount">
<HeaderStyle Width="5%"></HeaderStyle>
</asp:BoundColumn>
</Columns>
</asp:datagrid>
And here's the section of the C# code that is filling (or not filling) the datagrid (not that string strSQL is ommitted to save space):
Code:
private void btnSearch_Click(object sender, System.EventArgs e)
{
string strSQL;
using (OracleConnection dbConn = new OracleConnection(strLogin))
{
dbConn.Open();
using (OracleCommand dbCmd = new OracleCommand(strSQL))
{
dbCmd.Connection = dbConn;
dbCmd.CommandType = CommandType.Text;
dbAdp = new OracleDataAdapter();
dbAdp.SelectCommand = dbCmd;
DataSet dsGrants = new DataSet();
dbAdp.Fill(dsGrants, "result");
dgSearchResults.DataSource = dsGrants.Tables[0].DefaultView;
dgSearchResults.DataMember = "result";
dgSearchResults.DataBind();
lblError.Text = dsGrants.Tables[0].DefaultView.Count.ToString();
dbCmd.Dispose();
}
dbConn.Close();
dbConn.Dispose();
}
}
The grid is output, there are four rows with five cells in each row, but there is no data in the cell. I know the data is being returned as I output the number of records returned in the lblError label.
Can anyone give me an idea as to where I've gone wrong here? I'm assuming it's something small that I'm missing, but I've looked through a plethora of tutorials and guides on this and can't see what I'm overlooking.
Thanks very much in advance.
Cheers,
Pablo