Saturday, March 24, 2012
populate my datagrid RESOLVED
wots going on there then here is the code,
Imports System
Imports System.data
Imports System.Data.SqlClient
Public Class WebForm1
Inherits System.Web.UI.Page
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Protected WithEvents txt_mobile_number As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_name As System.Web.UI.WebControls.TextBox
Protected WithEvents btn_submit As System.Web.UI.WebControls.Button
Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid
'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
' declare the data set and data adapters
Private dsUsers As New DataSet
Private daUsers As New SqlDataAdapter
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub loadusers()
'connect to database
Dim oSQLConn As SqlConnection = New SqlConnection
oSQLConn.ConnectionString = "Data Source=(local);" & _
"Initial Catalog=Con_Test;" & _
"Integrated Security=SSPI"
oSQLConn.Open()
'databind the infromation
'If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
daUsers.SelectCommand = New SqlCommand("SELECT * from table_user", oSQLConn)
daUsers.Fill(dsUsers, "Mobile")
DataGrid1.DataSource = dsUsers.Tables(0)
DataGrid1.DataBind()
oSQLConn.Close()
'daUsers.Fill(dsUsers)
'DataGrid1.DataSource = dsUsers.Tables(0)
End Sub
End ClassDoes your dataset contain any data ?
If there is no row in the DataTable, you will not see the Datagrid on the page.
im trying to fill my datagrid but when the page loads in the browser you cant even see it.
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
What else do you expect with an empty Page_Load event :p
ii called loadusers now in the page load an now i am gettin an error that
'invalid object name table_user', thats the table name within Con_test.
:eek2:
Has it been spelt right in the database?
top man mendhank, i know it seemed obvious with the error message but i never would have checked it,
u da man
Not a problem, we all learn... :)
Wednesday, March 21, 2012
Populate Textboxes?
Sub Page_Load()
Dim oRandom As New Random()
Dim iNum As Integer
iNum = oRandom.Next(1, 100000)
textbox1.text = iNum
end sub
I run the page and the textbox is still blank.Is the textbox standalone in the page, or is it nested in a formview?
Can you put anything in the textbox, i.e. textbox.text = "something"
no its not letting me put textbox1.text ="anything" ... I do have it between Form tags...
Im lost
Is it supposed to populate on page load? If so do you have te call inside an if not isportback...
yea I would like for it to populate on the page load
In that case, on the page load sub, add the following:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
'Put all your page load stuff in here including the textbox piece
Dim oRandom As New Random()
Dim iNum As Integer
iNum = oRandom.Next(1, 100000)
textbox1.text = iNum
End If
End Sub
bah Im an idiot... lol... thanks...
Anjari
populating a dropdown list from arraylist of objects
i have an arraylist which holds my Customer object, that contains the
customer details, but when i try binding it to a dropdown box, i cant get
the values to appear..
this is what i tried:
customerList.DataSource = Customer.GetAdminList()
customerList.DataBind()
customerList.DataTextField = CType(customerList.DataSource,
Customer).Email.ToString
customerList.DataValueField = CType(customerList.DataSource,
Customer).CustomerID.ToString
customerList.Items.Insert(0, "--ALL CUSTOMERS--")
this error returns me a invalid cast error..so i also tried the normal
method:
customerList.DataSource = DotcoCustomer.GetAdminList()
customerList.DataBind()
customerList.DataTextField = "email"
customerList.DataValueField = "customerID"
customerList.Items.Insert(0, "--ALL CUSTOMERS--")
but this populates the dropdown list with the the values
"Web2004.Customer" - which is my application namespace.Object...'
any help appreciated,
Paul.Rearrange the order of your code:
customerList.DataSource = DotcoCustomer.GetAdminList()
customerList.DataTextField = "email"
customerList.DataValueField = "customerID"
customerList.DataBind()
customerList.Items.Insert(0, "--ALL CUSTOMERS--")
"Paul M" <milsnips@.hotmail.com> wrote in message
news:uf9aWLvQEHA.3568@.TK2MSFTNGP10.phx.gbl...
> hi there,
> i have an arraylist which holds my Customer object, that contains the
> customer details, but when i try binding it to a dropdown box, i cant get
> the values to appear..
> this is what i tried:
> customerList.DataSource = Customer.GetAdminList()
> customerList.DataBind()
> customerList.DataTextField = CType(customerList.DataSource,
> Customer).Email.ToString
> customerList.DataValueField = CType(customerList.DataSource,
> Customer).CustomerID.ToString
> customerList.Items.Insert(0, "--ALL CUSTOMERS--")
> this error returns me a invalid cast error..so i also tried the normal
> method:
>
> customerList.DataSource = DotcoCustomer.GetAdminList()
> customerList.DataBind()
> customerList.DataTextField = "email"
> customerList.DataValueField = "customerID"
> customerList.Items.Insert(0, "--ALL CUSTOMERS--")
>
> but this populates the dropdown list with the the values
> "Web2004.Customer" - which is my application namespace.Object...'
> any help appreciated,
> Paul.
>
>
populating a dropdown list from arraylist of objects
i have an arraylist which holds my Customer object, that contains the
customer details, but when i try binding it to a dropdown box, i cant get
the values to appear..
this is what i tried:
customerList.DataSource = Customer.GetAdminList()
customerList.DataBind()
customerList.DataTextField = CType(customerList.DataSource,
Customer).Email.ToString
customerList.DataValueField = CType(customerList.DataSource,
Customer).CustomerID.ToString
customerList.Items.Insert(0, "--ALL CUSTOMERS--")
this error returns me a invalid cast error..so i also tried the normal
method:
customerList.DataSource = DotcoCustomer.GetAdminList()
customerList.DataBind()
customerList.DataTextField = "email"
customerList.DataValueField = "customerID"
customerList.Items.Insert(0, "--ALL CUSTOMERS--")
but this populates the dropdown list with the the values
"Web2004.Customer" - which is my application namespace.Object...??
any help appreciated,
Paul.Rearrange the order of your code:
customerList.DataSource = DotcoCustomer.GetAdminList()
customerList.DataTextField = "email"
customerList.DataValueField = "customerID"
customerList.DataBind()
customerList.Items.Insert(0, "--ALL CUSTOMERS--")
"Paul M" <milsnips@.hotmail.com> wrote in message
news:uf9aWLvQEHA.3568@.TK2MSFTNGP10.phx.gbl...
> hi there,
> i have an arraylist which holds my Customer object, that contains the
> customer details, but when i try binding it to a dropdown box, i cant get
> the values to appear..
> this is what i tried:
> customerList.DataSource = Customer.GetAdminList()
> customerList.DataBind()
> customerList.DataTextField = CType(customerList.DataSource,
> Customer).Email.ToString
> customerList.DataValueField = CType(customerList.DataSource,
> Customer).CustomerID.ToString
> customerList.Items.Insert(0, "--ALL CUSTOMERS--")
> this error returns me a invalid cast error..so i also tried the normal
> method:
>
> customerList.DataSource = DotcoCustomer.GetAdminList()
> customerList.DataBind()
> customerList.DataTextField = "email"
> customerList.DataValueField = "customerID"
> customerList.Items.Insert(0, "--ALL CUSTOMERS--")
>
> but this populates the dropdown list with the the values
> "Web2004.Customer" - which is my application namespace.Object...??
> any help appreciated,
> Paul.