473,416 Members | 1,659 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

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 2849
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

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

Similar topics

2
by: Randy Fraser | last post by:
Is anyone using a datagrid for data entry? All I am trying to do is create a grid where the user enters an Item Number and the rest of the grid displays the information such as Description. ...
2
by: Ray Booysen | last post by:
Hi all I have a collection of Invoices that I bind to a datagrid. Some of these invoices have been processed and you can tell this via a property in the invoice class called DateProcessed. If...
2
by: marty | last post by:
I did some searchs, but can't find the answer to my problems. I have a editable DataGrid. I do an update of one of the rows. Postback "OnUpdateCommand" Call Oracle proc to do that actual...
0
by: Sridhar | last post by:
Hi, I have a Crystal Report which has two sub reports in it. When I try to view this Crystal Report in my local computer, it is showing data for sub reports also. But when I deploy it to the web...
2
by: teo | last post by:
I have Datagrid on an aspx page. The datagrid has data distribued on several page (that is it has navigation buttons). Question: After the data are displayed on the Datagrid, all the data...
0
by: cms3023 | last post by:
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. The table inside the database has data that matches with...
0
by: mvanroshum | last post by:
Hi, I have the following problem: The DataSource of a DataGrid can be set to an IList. The DataGrid nicely lists the objects in the IList, showing all the public properties of the objects as...
4
by: =?Utf-8?B?UmludSBHb3BhbGFrcmlzaG5hIFBpbGxhaQ==?= | last post by:
Hi All, I have an application that fetch data thru a store proc and display in a datagrid, but after successful execution of proc the data grid is not visible.Please go thru the following code...
1
by: chandan | last post by:
Hi All! How to Export Datagrid view data to excel in ASP.net 3.5? Thanks, Chandan
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.