468,133 Members | 1,211 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,133 developers. It's quick & easy.

DataGrid not showing data

nmm32
9
I have a DataGrid which displays data with the aid of a procedure.

I have tested the procedure inside the database and it is working fine.
I have another procedure which adds another row to the table, which is working fine inside the programming, and in the database.

However, I still cannot figure out what am I doing wrong with the DataGrid configurations OR Database OR DataAdapter OR SqlSelectCommand ... I really don't know yet and I have spent a lot of time in this tiny issue.

Below is additional information. Any help is extremely appreciated.

**On page Load a different page calls the method RefreshDataCriteria, which it supposes to refresh the data in the DataGrid***

I have other pages that do the same thing:
when the user clicks on a certain link, in the main page, the link makes visible the control ( .ascx ) and then calls the function to refresh the data of the DataGrid. The other pages are working fine, except for this one.

----------------------------------------------------------
Code inside the HTML part:
[HTML]
<asp:datagrid id=dataGridCriteria Width="466px" runat="server" Font-Size="XX-Small" DataKeyField="CourseCriteriaID" DataMember="procWebSelectCourseCriteriaForSyllabus " DataSource="<%# DtsCourseCriterias31 %>" BorderColor="#3366CC" BorderWidth="1px" BackColor="White" CellPadding="4" BorderStyle="None" AutoGenerateColumns="False" PageSize="5" Font-Names="sans-serif" AllowPaging="True" Height="120px">
<SelectedItemStyle Font-Bold="True" ForeColor="#CCFF99" BackColor="#009999"></SelectedItemStyle>
<ItemStyle Font-Size="XX-Small" Font-Names="Arial" Font-Bold="True" ForeColor="#003399" BackColor="White"></ItemStyle>
<HeaderStyle Font-Size="XX-Small" Font-Names="Arial" Font-Bold="True" ForeColor="#CCCCFF" BackColor="#003399"></HeaderStyle>
<FooterStyle ForeColor="#003399" BackColor="#99CCCC"></FooterStyle>
<Columns>
<asp:BoundColumn DataField="ProfOrgCriteriaID" HeaderText="ProfOrgCriteriaID"></asp:BoundColumn>
<asp:BoundColumn DataField="ProfOrgCriteriaCode" HeaderText="ProfOrgCriteriaCode"></asp:BoundColumn>
<asp:BoundColumn DataField="ProfOrgCriteriaDescr" HeaderText="ProfOrgCriteriaDescr"></asp:BoundColumn>
<asp:BoundColumn DataField="CourseCriteriaID" HeaderText="CourseCriteriaID"></asp:BoundColumn>
<asp:ButtonColumn Text="Delete" CommandName="Delete">
<HeaderStyle Width="50px"></HeaderStyle>
</asp:ButtonColumn>
</Columns>
<PagerStyle NextPageText="Next Page" PrevPageText="Previous Page" HorizontalAlign="Center" ForeColor="#003399"
BackColor="#99CCCC"></PagerStyle>
</asp:datagrid>[/HTML]
-----------------------------------------------------------------------

Procedure:

Expand|Select|Wrap|Line Numbers
  1. CREATE PROCEDURE dbo.procWebSelectCourseCriteriaForSyllabus
  2.  
  3. @CourseCode varchar(20)
  4.  
  5. AS
  6.  
  7. SELECT     ProfOrgCriteria.ProfOrgCriteriaID, ProfOrgCriteria.ProfOrgCriteriaCode,ProfOrgCriteria.ProfOrgCriteriaDescr,CourseCriteria.CourseCriteriaID
  8. FROM         CourseCriteria INNER JOIN
  9.                       ProfOrgCriteria ON CourseCriteria.ProfOrgCriteriaID = ProfOrgCriteria.ProfOrgCriteriaID
  10. WHERE     (CourseCriteria.CourseCode = @CourseCode)
  11. GO
---------------------------------------------------------

DataSet:

[HTML]<?xml version="1.0" standalone="yes"?>
<xs:schema id="dtsCourseCriterias3" targetNamespace="http://www.tempuri.org/dtsCourseCriterias3.xsd" xmlns:mstns="http://www.tempuri.org/dtsCourseCriterias3.xsd" xmlns="http://www.tempuri.org/dtsCourseCriterias3.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" attributeFormDefault="qualified" elementFormDefault="qualified">
<xs:element name="dtsCourseCriterias3" msdata:IsDataSet="true">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="procWebSelectCourseCriteriaForSyllabus">
<xs:complexType>
<xs:sequence>
<xs:element name="ProfOrgCriteriaID" msdata:ReadOnly="true" msdata:AutoIncrement="true" type="xs:int" />
<xs:element name="ProfOrgCriteriaCode" type="xs:string" />
<xs:element name="ProfOrgCriteriaDescr" type="xs:string" />
<xs:element name="CourseCriteriaID" msdata:ReadOnly="true" msdata:AutoIncrement="true" type="xs:int" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Table">
<xs:complexType>
<xs:sequence>
<xs:element name="ProfOrgCriteriaID" msdata:ReadOnly="true" msdata:AutoIncrement="true" type="xs:int" />
<xs:element name="ProfOrgCriteriaCode" type="xs:string" />
<xs:element name="ProfOrgCriteriaDescr" type="xs:string" />
<xs:element name="CourseCriteriaID" msdata:ReadOnly="true" msdata:AutoIncrement="true" type="xs:int" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
<xs:unique name="dtsCourseCriterias3Key1" msdata:PrimaryKey="true">
<xs:selector xpath=".//mstns:procWebSelectCourseCriteriaForSyllabus" />
<xs:field xpath="mstns:ProfOrgCriteriaID" />
<xs:field xpath="mstns:CourseCriteriaID" />
</xs:unique>
<xs:unique name="Constraint1" msdata:PrimaryKey="true">
<xs:selector xpath=".//mstns:Table" />
<xs:field xpath="mstns:ProfOrgCriteriaID" />
<xs:field xpath="mstns:CourseCriteriaID" />
</xs:unique>
</xs:element>
</xs:schema>[/HTML]

-----------------------------------------

VB.NET Code:


Expand|Select|Wrap|Line Numbers
  1. Public Class CourseCriteriaGrid
  2.     Inherits System.Web.UI.UserControl
  3.  
  4. #Region " Web Form Designer Generated Code "
  5.  
  6.     'This call is required by the Web Form Designer.
  7.     <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
  8.         Dim configurationAppSettings As System.Configuration.AppSettingsReader = New System.Configuration.AppSettingsReader
  9.         Me.SqlConnection1 = New System.Data.SqlClient.SqlConnection
  10.         Me.sqlSelectCourseCriteria = New System.Data.SqlClient.SqlCommand
  11.         Me.SqlCommandAddCourseCriteria = New System.Data.SqlClient.SqlCommand
  12.         Me.DtsCourseCriterias31 = New UniversalSyllabus.dtsCourseCriterias3
  13.         Me.SqlDataAdapterCourseCriteria = New System.Data.SqlClient.SqlDataAdapter
  14.         Me.sqlCommandDeleteCourseCriteria = New System.Data.SqlClient.SqlCommand
  15.         CType(Me.DtsCourseCriterias31, System.ComponentModel.ISupportInitialize).BeginInit()
  16.         '
  17.         'SqlConnection1
  18.         '
  19.         Me.SqlConnection1.ConnectionString = CType(configurationAppSettings.GetValue("SqlConnection1.ConnectionString", GetType(System.String)), String)
  20.         '
  21.         'sqlSelectCourseCriteria
  22.         '
  23.         Me.sqlSelectCourseCriteria.CommandText = "[procWebSelectCourseCriteriaForSyllabus]"
  24.         Me.sqlSelectCourseCriteria.CommandType = System.Data.CommandType.StoredProcedure
  25.         Me.sqlSelectCourseCriteria.Connection = Me.SqlConnection1
  26.         Me.sqlSelectCourseCriteria.Parameters.Add(New System.Data.SqlClient.SqlParameter("@RETURN_VALUE", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.ReturnValue, False, CType(0, Byte), CType(0, Byte), "", System.Data.DataRowVersion.Current, Nothing))
  27.         Me.sqlSelectCourseCriteria.Parameters.Add(New System.Data.SqlClient.SqlParameter("@CourseCode", System.Data.SqlDbType.VarChar, 20))
  28.         '
  29.         'SqlCommandAddCourseCriteria
  30.         '
  31.         Me.SqlCommandAddCourseCriteria.CommandText = "[procWebInsertCourseCriteria]"
  32.         Me.SqlCommandAddCourseCriteria.CommandType = System.Data.CommandType.StoredProcedure
  33.         Me.SqlCommandAddCourseCriteria.Connection = Me.SqlConnection1
  34.         Me.SqlCommandAddCourseCriteria.Parameters.Add(New System.Data.SqlClient.SqlParameter("@RETURN_VALUE", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.ReturnValue, False, CType(0, Byte), CType(0, Byte), "", System.Data.DataRowVersion.Current, Nothing))
  35.         Me.SqlCommandAddCourseCriteria.Parameters.Add(New System.Data.SqlClient.SqlParameter("@CourseCode", System.Data.SqlDbType.VarChar, 20))
  36.         Me.SqlCommandAddCourseCriteria.Parameters.Add(New System.Data.SqlClient.SqlParameter("@ProfOrgCriteriaID", System.Data.SqlDbType.Int, 4))
  37.         '
  38.         'DtsCourseCriterias31
  39.         '
  40.         Me.DtsCourseCriterias31.DataSetName = "dtsCourseCriterias3"
  41.         Me.DtsCourseCriterias31.EnforceConstraints = False
  42.         Me.DtsCourseCriterias31.Locale = New System.Globalization.CultureInfo("en-US")
  43.         '
  44.         'SqlDataAdapterCourseCriteria
  45.         '
  46.         Me.SqlDataAdapterCourseCriteria.SelectCommand = Me.sqlSelectCourseCriteria
  47.         '
  48.         'sqlCommandDeleteCourseCriteria
  49.         '
  50.         Me.sqlCommandDeleteCourseCriteria.CommandText = "[procWebDeleteCourseCriteria]"
  51.         Me.sqlCommandDeleteCourseCriteria.CommandType = System.Data.CommandType.StoredProcedure
  52.         Me.sqlCommandDeleteCourseCriteria.Connection = Me.SqlConnection1
  53.         Me.sqlCommandDeleteCourseCriteria.Parameters.Add(New System.Data.SqlClient.SqlParameter("@RETURN_VALUE", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.ReturnValue, False, CType(0, Byte), CType(0, Byte), "", System.Data.DataRowVersion.Current, Nothing))
  54.         Me.sqlCommandDeleteCourseCriteria.Parameters.Add(New System.Data.SqlClient.SqlParameter("@CourseCriteriaID", System.Data.SqlDbType.Int, 4))
  55.         CType(Me.DtsCourseCriterias31, System.ComponentModel.ISupportInitialize).EndInit()
  56.  
  57.     End Sub
  58.  
  59.     Protected WithEvents SqlConnection1 As System.Data.SqlClient.SqlConnection
  60.     '  Protected WithEvents DtsCourseCriterias1 As UniversalSyllabus.dtsCourseCriterias3
  61.     Protected WithEvents sqlSelectCourseCriteria As System.Data.SqlClient.SqlCommand
  62.     Protected WithEvents SqlCommandAddCourseCriteria As System.Data.SqlClient.SqlCommand
  63.     Protected WithEvents DtsCourseCriterias31 As UniversalSyllabus.dtsCourseCriterias3
  64.     Protected WithEvents SqlDataAdapterCourseCriteria As System.Data.SqlClient.SqlDataAdapter
  65.     Protected WithEvents Label1 As System.Web.UI.WebControls.Label
  66.     Protected WithEvents dataGridCriteria As System.Web.UI.WebControls.DataGrid
  67.     Protected WithEvents buttonAddCriteria As System.Web.UI.WebControls.Button
  68.     Protected WithEvents sqlCommandDeleteCourseCriteria As System.Data.SqlClient.SqlCommand
  69.  
  70.     'NOTE: The following placeholder declaration is required by the Web Form Designer.
  71.     'Do not delete or move it.
  72.     Private designerPlaceholderDeclaration As System.Object
  73.  
  74.     Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
  75.         'CODEGEN: This method call is required by the Web Form Designer
  76.         'Do not modify it using the code editor.
  77.         InitializeComponent()
  78.     End Sub
  79.  
  80. #End Region
  81.  
  82.     Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  83.  
  84.  
  85.     End Sub
  86.  
  87.     Public Sub RefreshDataCriteria()
  88.         Me.DtsCourseCriterias31.Clear()
  89.         Me.sqlSelectCourseCriteria.Parameters("@CourseCode").Value = Session("CourseCode")
  90.         Me.SqlDataAdapterCourseCriteria.Fill(Me.DtsCourseCriterias31)
  91.         Me.dataGridCriteria.DataBind()
  92.  
  93.     End Sub
  94.  
  95.     Public Event addCriteria()
  96.  
  97.  
  98.     Private Sub buttonAddCriteria_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles buttonAddCriteria.Click
  99.         RaiseEvent addCriteria()
  100.  
  101.     End Sub
  102.  
  103.     Private Sub dataGridCriteria_ItemDataBound(ByVal sender As System.Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs)
  104.         'Enable javascript to alert about the delete
  105.         If e.Item.ItemType <> ListItemType.Header And _
  106.         e.Item.ItemType <> ListItemType.Footer And e.Item.ItemType <> ListItemType.Pager Then
  107.             Dim deleteButton2 As LinkButton = e.Item.Cells(2).Controls(0)
  108.             deleteButton2.Attributes("onclick") = "javascript:return " & _
  109.             "confirm('Are you sure you want to delete Course Criteria: " & _
  110.             DataBinder.Eval(e.Item.DataItem, "CriteriaDescription") & " ?')"
  111.         End If
  112.  
  113.     End Sub
  114.  
  115.  
  116.     Private Sub dataGridCriteria_PageIndexChanged(ByVal source As System.Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs)
  117.         Me.dataGridCriteria.CurrentPageIndex = e.NewPageIndex
  118.         RefreshDataCriteria()
  119.     End Sub
  120.  
  121.  
  122.     Private Sub dataGridCriteria_ItemCommand(ByVal source As System.Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs)
  123.         Select Case (CType(e.CommandSource, LinkButton)).CommandName
  124.             Case "Delete"
  125.                 Me.sqlCommandDeleteCourseCriteria.Parameters("@CourseCriteriaID").Value = Me.dataGridCriteria.DataKeys(e.Item.ItemIndex)
  126.                 Me.SqlConnection1.Open()
  127.                 Me.sqlCommandDeleteCourseCriteria.ExecuteNonQuery()
  128.                 Me.SqlConnection1.Close()
  129.  
  130.                 Me.dataGridCriteria.EditItemIndex = -1
  131.  
  132.                 If Me.dataGridCriteria.CurrentPageIndex >= 1 And Me.dataGridCriteria.Items.Count = 1 Then
  133.                     Me.dataGridCriteria.CurrentPageIndex = Me.dataGridCriteria.CurrentPageIndex - 1
  134.  
  135.                 End If
  136.  
  137.                 RefreshDataCriteria()
  138.         End Select
  139.     End Sub
  140.  
  141.  
  142. End Class
-------------------------------------

Thank you!,
NMM
May 20 '07 #1
5 2521
kenobewan
4,871 Expert 4TB
Sounds like you have a postback problem.
May 20 '07 #2
nmm32
9
I have added the code..
Expand|Select|Wrap|Line Numbers
  1. Private Sub Page_Load
  2. (ByVal sender As System.Object, ByVal e As  System.EventArgs) Handles MyBase.Load
  3.  
  4.         If Not IsPostBack Then
  5.             RefreshDataCriteria()
  6.         End If
  7.     End Sub
But still does not work.
I even have tried it without the "if not ispostback".
May 20 '07 #3
try debugging the value which is being send to SP. It appear that datatype is mismatching as a result the where condition is not showing a result , which in turn is null.
May 21 '07 #4
nmm32
9
try debugging the value which is being send to SP. It appear that datatype is mismatching as a result the where condition is not showing a result , which in turn is null.
Thanks. I tried that, but it is passing the correct data.
Ok, I solved the problem, but not with the DataGrid. I chose a different control (ListBox) and arranged the programming so that the ListBox, with two buttons, can do the same thing that the DataGrid was supposed to do. Not a "pretty" box, but well, they must get along with it now.

....I have not yet figured out what happened with the DataGrid. Someone told me to call the method Me.DataBind in Page Load(). .. got to check that out.
May 21 '07 #5
Plater
7,872 Expert 4TB
Anytime you change the .DataSource property, you must also call the .DataBind() function to complete the change.
I only use a few lines of code for it.
Expand|Select|Wrap|Line Numbers
  1. DataTable dt=globalDBFunctions.GetMyData();
  2. Mygridview.DataSource=dt;
  3. Mygridview.DataBind();
  4.  
May 21 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Randy Fraser | last post: by
2 posts views Thread by Ray Booysen | last post: by
2 posts views Thread by marty | last post: by
2 posts views Thread by teo | last post: by
reply views Thread by cms3023 | last post: by
4 posts views Thread by =?Utf-8?B?UmludSBHb3BhbGFrcmlzaG5hIFBpbGxhaQ==?= | last post: by
27 posts views Thread by didacticone | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.