Showing posts with label datagrid. Show all posts
Showing posts with label datagrid. Show all posts

Thursday, March 29, 2012

Pop Up/Refresh Issue

I have a parent page that contains a datagrid. On this page is a link to "Add New" record. I have done this by opening a child/pop up so they can enter the data in a new window. When the user submits, the parent page reloads and refreshes the data. Here is the code in the child page:

btnAdd.Attributes.Add("onclick", "window.opener.location.reload();");

I kinda have two problems here, one I can live with...for now.

Problem 1: When the page reloads, the user has to click "Retry". This works, but is a bit sloppy. I've searched a few different methods on this forum, but none seem to submit and refresh my data. (I can't simply refresh because I have a few panels on the parent that throw a wrench into it)

Problem 2: The line that I posted earlier is fine, and works well; however I do have some validation (server side) on the child form. If the validation in the btnAdd_Click event isn't a success, I would like to avoid reloading the parent. How would I go about doing that?

Thanks.

Just to clarify a bit, I want to check a condition before I have my js reload the parent page.

Let's say:

If (someCondition)

{

//reload parent page

}

else

{

// don't reload parent page

}

Any suggestions?


Instead of spamming the forum with much of the same problem, I'll add to this one.

I would also like to somehow clear the last submmited button on the parent from the child. Let me try to explain.

On the parent the user may press a button which kicks off validation on the server. If validation on the server fails, a message on the page is displayed. (Parent) Now, if the user decides to add a record at this time via the pop up or child, hitting update on the child will reload the parent page; however, in this case my grid on the parent won't refresh because it's executing the submit on the parent. Therefore displaying "validation failed", when in fact it didn't.

Eh, I know this probably sounds messy, but if someone can help with this or any of my other pop up/refresh problems in this thread, I would appreciate it.


I don't know of this is going to help you or not but here is my 2cents. On the child pop up page when the user submits the informationyou can send a value of true to the parent which will represent thatthe child form has been submitted. This value can be send usingQueryString or Session State. When the parent page recieves thisinformation it can referesh it.
Does that help ?

Populate 2 or more datagrids from one OleDBCommand

Hi All,

I wish to populate more than one datagrid from the same OleDBCommand. The
code I have is:

Dim objCmd As New OleDbCommand(strSql, objConn)

Then...

Me.dgTariffHolidayHomesBand1.DataSource = objCmd.ExecuteReader()
Me.dgTariffHolidayHomesBand1.Visible = True
Me.dgTariffHolidayHomesBand2.DataSource = objCmd.ExecuteReader()
Me.dgTariffHolidayHomesBand2.Visible = True

I get this error when the second call to objCmd.ExecuteReader() is called:
System.InvalidOperationException: ExecuteReader requires an open and
available Connection.

The reason for populating multiple grids from the same data, is that I am
calling ALL columns in the SQL, and then using (for example) columns A and
B
in DG1, C and D in DG2...and so on.

Surely I don't need a new recordset for each datagrid?

Simon.There are a couple problems with your approach.

First, the ExecuteReader method requires that you close and re-open the
connection, just as the code implies but you can't use a DataReader as the
DataSource for a DataGrid. You need something that implements IList or
IListSource. You can research both of those interfaces in the MSDN Library
to see what classes implement them.

Another problem is that you're making two queries to the database and
populating the DataGrids sequentially. What happens if the data changes
between calls? You can't be sure the data in the DataGrids will match.
What you need to do is get the data once, using a DataSet or even a
DataTable and set both DataGrids to use the same DataSource.

Hope this helps,

DalePres
MCAD, MCSE, MCDBA

"Simon Harris" <too-much-spam@.makes-you-fat.com> wrote in message
news:ODOqdixBFHA.1400@.TK2MSFTNGP11.phx.gbl...
> Hi All,
> I wish to populate more than one datagrid from the same OleDBCommand. The
> code I have is:
> Dim objCmd As New OleDbCommand(strSql, objConn)
> Then...
> Me.dgTariffHolidayHomesBand1.DataSource = objCmd.ExecuteReader()
> Me.dgTariffHolidayHomesBand1.Visible = True
> Me.dgTariffHolidayHomesBand2.DataSource = objCmd.ExecuteReader()
> Me.dgTariffHolidayHomesBand2.Visible = True
> I get this error when the second call to objCmd.ExecuteReader() is called:
> System.InvalidOperationException: ExecuteReader requires an open and
> available Connection.
> The reason for populating multiple grids from the same data, is that I am
> calling ALL columns in the SQL, and then using (for example) columns A and
> B
> in DG1, C and D in DG2...and so on.
> Surely I don't need a new recordset for each datagrid?
> Simon.

Populate 2 or more datagrids from one OleDBCommand

Hi All,
I wish to populate more than one datagrid from the same OleDBCommand. The
code I have is:
Dim objCmd As New OleDbCommand(strSql, objConn)
Then...
Me.dgTariffHolidayHomesBand1.DataSource = objCmd.ExecuteReader()
Me.dgTariffHolidayHomesBand1.Visible = True
Me.dgTariffHolidayHomesBand2.DataSource = objCmd.ExecuteReader()
Me.dgTariffHolidayHomesBand2.Visible = True
I get this error when the second call to objCmd.ExecuteReader() is called:
System.InvalidOperationException: ExecuteReader requires an open and
available Connection.
The reason for populating multiple grids from the same data, is that I am
calling ALL columns in the SQL, and then using (for example) columns A and
B
in DG1, C and D in DG2...and so on.
Surely I don't need a new recordset for each datagrid?
Simon.There are a couple problems with your approach.
First, the ExecuteReader method requires that you close and re-open the
connection, just as the code implies but you can't use a DataReader as the
DataSource for a DataGrid. You need something that implements IList or
IListSource. You can research both of those interfaces in the MSDN Library
to see what classes implement them.
Another problem is that you're making two queries to the database and
populating the DataGrids sequentially. What happens if the data changes
between calls? You can't be sure the data in the DataGrids will match.
What you need to do is get the data once, using a DataSet or even a
DataTable and set both DataGrids to use the same DataSource.
Hope this helps,
DalePres
MCAD, MCSE, MCDBA
"Simon Harris" <too-much-spam@.makes-you-fat.com> wrote in message
news:ODOqdixBFHA.1400@.TK2MSFTNGP11.phx.gbl...
> Hi All,
> I wish to populate more than one datagrid from the same OleDBCommand. The
> code I have is:
> Dim objCmd As New OleDbCommand(strSql, objConn)
> Then...
> Me.dgTariffHolidayHomesBand1.DataSource = objCmd.ExecuteReader()
> Me.dgTariffHolidayHomesBand1.Visible = True
> Me.dgTariffHolidayHomesBand2.DataSource = objCmd.ExecuteReader()
> Me.dgTariffHolidayHomesBand2.Visible = True
> I get this error when the second call to objCmd.ExecuteReader() is called:
> System.InvalidOperationException: ExecuteReader requires an open and
> available Connection.
> The reason for populating multiple grids from the same data, is that I am
> calling ALL columns in the SQL, and then using (for example) columns A and
> B
> in DG1, C and D in DG2...and so on.
> Surely I don't need a new recordset for each datagrid?
> Simon.
>

Populate a DataGrid from Multiple Databases - Order Problem

I have 4 different databases that I'm having to pull data from in order
to populate a datagrid. I am able to do this, but my problem is that
because I'm pulling the data from 4 different databases, the data is
ordered alphabetically but is grouped by database.

Here is an example of what is happening to the data in the datgrid with
the code that I have now.
DB1 Apple
DB1 Bird
DB1 Cake
DB2 Airplane
DB2 Boat
DB2 Circle
DB3 Amazing
DB3 Blue
etc....

I want ALL the data in the datagrid ordered alphabetically, reguardless
of which database it is from.

This is the code that I'm using to bind data to my datagrid. Can I add
something to my code to order the data correctly or do I need to go
about this another way?

Private Sub BindData()

GetConnectionString()

Dim strSQL As String = "SELECT DISTINCT DB_PDESCR, DB_PPROD
FROM PUB.PCFPOLCY "
Dim strWhere As String = ""
Dim strOrderBy As String = ""

Dim tmpID As String = Request.QueryString("ID")

'Ensure that the ID is 4 charactes long
While Len(Trim(tmpID)) < 4
tmpID = "0" & Trim(tmpID)
End While

strWhere = " WHERE DB_PPROD = '" & Trim(tmpID) & "'"
strOrderBy = " ORDER BY DB_PDESCR"
strSQL = strSQL & strWhere & strOrderBy

Dim myDA As New OdbcDataAdapter
Dim myDS As New DataSet
Dim myCommand_amfnat As New OdbcCommand(strSQL,
amfnat_OdbcConnection)
Dim myCommand_msba As New OdbcCommand(strSQL,
msba_OdbcConnection)
Dim myCommand_bcam As New OdbcCommand(strSQL,
bcam_OdbcConnection)
Dim myCommand_afca As New OdbcCommand(strSQL,
afca_OdbcConnection)

'Create the DataAdapter for AMFNAT and Populate the DataSet
myDA.SelectCommand = myCommand_amfnat
myDA.Fill(myDS)

'Create the DataAdapter for MSBA and Populate the DataSet
myDA.SelectCommand = myCommand_msba
myDA.Fill(myDS)

'Create the DataAdapter for BCAM and Populate the DataSet
myDA.SelectCommand = myCommand_bcam
myDA.Fill(myDS)

'Create the DataAdapter for AFCA and Populate the DataSet
myDA.SelectCommand = myCommand_afca
myDA.Fill(myDS)

'Set the datagrid's datasource to the dataset and databind
dgAllCompanies.DataSource = myDS
dgAllCompanies.DataBind()

'Display error message if there are no records.
If myDS.Tables(0).Rows.Count = 0 Then
lblNoResults.Visible = True
dgAllCompanies.Visible = False
Else
lblNoResults.Visible = False
dgAllCompanies.Visible = True
End If

''*** Clean Up
myDS.Dispose()
myDS = Nothing

myDA.Dispose()
myDA = Nothing

myCommand_amfnat.Dispose()
myCommand_amfnat = Nothing

myCommand_msba.Dispose()
myCommand_msba = Nothing

myCommand_bcam.Dispose()
myCommand_bcam = Nothing

myCommand_afca.Dispose()
myCommand_afca = Nothing

End Sub

Thanks for taking the time to look at my problem!
Crjunkyou can create your own custom class and implement icomparable interface
, then use arraylist to bind data to datagrid

crjunk wrote:
> I have 4 different databases that I'm having to pull data from in order
> to populate a datagrid. I am able to do this, but my problem is that
> because I'm pulling the data from 4 different databases, the data is
> ordered alphabetically but is grouped by database.
> Here is an example of what is happening to the data in the datgrid with
> the code that I have now.
> DB1 Apple
> DB1 Bird
> DB1 Cake
> DB2 Airplane
> DB2 Boat
> DB2 Circle
> DB3 Amazing
> DB3 Blue
> etc....
> I want ALL the data in the datagrid ordered alphabetically, reguardless
> of which database it is from.
> This is the code that I'm using to bind data to my datagrid. Can I add
> something to my code to order the data correctly or do I need to go
> about this another way?
> Private Sub BindData()
> GetConnectionString()
> Dim strSQL As String = "SELECT DISTINCT DB_PDESCR, DB_PPROD
> FROM PUB.PCFPOLCY "
> Dim strWhere As String = ""
> Dim strOrderBy As String = ""
> Dim tmpID As String = Request.QueryString("ID")
> 'Ensure that the ID is 4 charactes long
> While Len(Trim(tmpID)) < 4
> tmpID = "0" & Trim(tmpID)
> End While
> strWhere = " WHERE DB_PPROD = '" & Trim(tmpID) & "'"
> strOrderBy = " ORDER BY DB_PDESCR"
> strSQL = strSQL & strWhere & strOrderBy
> Dim myDA As New OdbcDataAdapter
> Dim myDS As New DataSet
> Dim myCommand_amfnat As New OdbcCommand(strSQL,
> amfnat_OdbcConnection)
> Dim myCommand_msba As New OdbcCommand(strSQL,
> msba_OdbcConnection)
> Dim myCommand_bcam As New OdbcCommand(strSQL,
> bcam_OdbcConnection)
> Dim myCommand_afca As New OdbcCommand(strSQL,
> afca_OdbcConnection)
> 'Create the DataAdapter for AMFNAT and Populate the DataSet
> myDA.SelectCommand = myCommand_amfnat
> myDA.Fill(myDS)
> 'Create the DataAdapter for MSBA and Populate the DataSet
> myDA.SelectCommand = myCommand_msba
> myDA.Fill(myDS)
> 'Create the DataAdapter for BCAM and Populate the DataSet
> myDA.SelectCommand = myCommand_bcam
> myDA.Fill(myDS)
> 'Create the DataAdapter for AFCA and Populate the DataSet
> myDA.SelectCommand = myCommand_afca
> myDA.Fill(myDS)
> 'Set the datagrid's datasource to the dataset and databind
> dgAllCompanies.DataSource = myDS
> dgAllCompanies.DataBind()
> 'Display error message if there are no records.
> If myDS.Tables(0).Rows.Count = 0 Then
> lblNoResults.Visible = True
> dgAllCompanies.Visible = False
> Else
> lblNoResults.Visible = False
> dgAllCompanies.Visible = True
> End If
> ''*** Clean Up
> myDS.Dispose()
> myDS = Nothing
> myDA.Dispose()
> myDA = Nothing
> myCommand_amfnat.Dispose()
> myCommand_amfnat = Nothing
> myCommand_msba.Dispose()
> myCommand_msba = Nothing
> myCommand_bcam.Dispose()
> myCommand_bcam = Nothing
> myCommand_afca.Dispose()
> myCommand_afca = Nothing
> End Sub
>
> Thanks for taking the time to look at my problem!
> Crjunk
If you can put whole data from four databases into one
datatable, you can use dataview's (=
datatable.DefaultView) Sort property to sort all data.
Then you bind datagrid with the sorted dataview. It shows
alphabetically ordered data.

HTH

Elton Wang
elton_wang@.hotmail.com

>--Original Message--
>I have 4 different databases that I'm having to pull data
from in order
>to populate a datagrid. I am able to do this, but my
problem is that
>because I'm pulling the data from 4 different databases,
the data is
>ordered alphabetically but is grouped by database.
>Here is an example of what is happening to the data in
the datgrid with
>the code that I have now.
>DB1 Apple
>DB1 Bird
>DB1 Cake
>DB2 Airplane
>DB2 Boat
>DB2 Circle
>DB3 Amazing
>DB3 Blue
>etc....
>I want ALL the data in the datagrid ordered
alphabetically, reguardless
>of which database it is from.
>This is the code that I'm using to bind data to my
datagrid. Can I add
>something to my code to order the data correctly or do I
need to go
>about this another way?
> Private Sub BindData()
> GetConnectionString()
> Dim strSQL As String = "SELECT DISTINCT
DB_PDESCR, DB_PPROD
>FROM PUB.PCFPOLCY "
> Dim strWhere As String = ""
> Dim strOrderBy As String = ""
> Dim tmpID As String = Request.QueryString("ID")
> 'Ensure that the ID is 4 charactes long
> While Len(Trim(tmpID)) < 4
> tmpID = "0" & Trim(tmpID)
> End While
> strWhere = " WHERE DB_PPROD = '" & Trim(tmpID)
& "'"
> strOrderBy = " ORDER BY DB_PDESCR"
> strSQL = strSQL & strWhere & strOrderBy
> Dim myDA As New OdbcDataAdapter
> Dim myDS As New DataSet
> Dim myCommand_amfnat As New OdbcCommand(strSQL,
>amfnat_OdbcConnection)
> Dim myCommand_msba As New OdbcCommand(strSQL,
>msba_OdbcConnection)
> Dim myCommand_bcam As New OdbcCommand(strSQL,
>bcam_OdbcConnection)
> Dim myCommand_afca As New OdbcCommand(strSQL,
>afca_OdbcConnection)
> 'Create the DataAdapter for AMFNAT and Populate
the DataSet
> myDA.SelectCommand = myCommand_amfnat
> myDA.Fill(myDS)
> 'Create the DataAdapter for MSBA and Populate the
DataSet
> myDA.SelectCommand = myCommand_msba
> myDA.Fill(myDS)
> 'Create the DataAdapter for BCAM and Populate the
DataSet
> myDA.SelectCommand = myCommand_bcam
> myDA.Fill(myDS)
> 'Create the DataAdapter for AFCA and Populate the
DataSet
> myDA.SelectCommand = myCommand_afca
> myDA.Fill(myDS)
> 'Set the datagrid's datasource to the dataset and
databind
> dgAllCompanies.DataSource = myDS
> dgAllCompanies.DataBind()
> 'Display error message if there are no records.
> If myDS.Tables(0).Rows.Count = 0 Then
> lblNoResults.Visible = True
> dgAllCompanies.Visible = False
> Else
> lblNoResults.Visible = False
> dgAllCompanies.Visible = True
> End If
> ''*** Clean Up
> myDS.Dispose()
> myDS = Nothing
> myDA.Dispose()
> myDA = Nothing
> myCommand_amfnat.Dispose()
> myCommand_amfnat = Nothing
> myCommand_msba.Dispose()
> myCommand_msba = Nothing
> myCommand_bcam.Dispose()
> myCommand_bcam = Nothing
> myCommand_afca.Dispose()
> myCommand_afca = Nothing
> End Sub
>
>Thanks for taking the time to look at my problem!
>Crjunk
>.
Thanks Elton and ashish. I figured out that I could use a DataView
before I read your message after doing a bunch of searching. Thanks
for your help. Here is what I added/changed in my code.

'Create a DataView so that I can order the data before the
DataGrid is populated.
'Otherwise the data will be in alphabetical order in DataGrid,
but grouped by DataBase.
Dim dvArrange As DataView = myDS.Tables(0).DefaultView
dvArrange.Sort = "DB_PDESCR"

'Set the datagrid's datasource to the DataView and bind data.
dgAllCompanies.DataSource = dvArrange
dgAllCompanies.DataBind()

Monday, March 26, 2012

Populate a DataGrid from Multiple Databases - Order Problem

I have 4 different databases that I'm having to pull data from in order
to populate a datagrid. I am able to do this, but my problem is that
because I'm pulling the data from 4 different databases, the data is
ordered alphabetically but is grouped by database.
Here is an example of what is happening to the data in the datgrid with
the code that I have now.
DB1 Apple
DB1 Bird
DB1 Cake
DB2 Airplane
DB2 Boat
DB2 Circle
DB3 Amazing
DB3 Blue
etc....
I want ALL the data in the datagrid ordered alphabetically, reguardless
of which database it is from.
This is the code that I'm using to bind data to my datagrid. Can I add
something to my code to order the data correctly or do I need to go
about this another way?
Private Sub BindData()
GetConnectionString()
Dim strSQL As String = "SELECT DISTINCT DB_PDESCR, DB_PPROD
FROM PUB.PCFPOLCY "
Dim strWhere As String = ""
Dim strOrderBy As String = ""
Dim tmpID As String = Request.QueryString("ID")
'Ensure that the ID is 4 charactes long
While Len(Trim(tmpID)) < 4
tmpID = "0" & Trim(tmpID)
End While
strWhere = " WHERE DB_PPROD = '" & Trim(tmpID) & "'"
strOrderBy = " ORDER BY DB_PDESCR"
strSQL = strSQL & strWhere & strOrderBy
Dim myDA As New OdbcDataAdapter
Dim myDS As New DataSet
Dim myCommand_amfnat As New OdbcCommand(strSQL,
amfnat_OdbcConnection)
Dim myCommand_msba As New OdbcCommand(strSQL,
msba_OdbcConnection)
Dim myCommand_bcam As New OdbcCommand(strSQL,
bcam_OdbcConnection)
Dim myCommand_afca As New OdbcCommand(strSQL,
afca_OdbcConnection)
'Create the DataAdapter for AMFNAT and Populate the DataSet
myDA.SelectCommand = myCommand_amfnat
myDA.Fill(myDS)
'Create the DataAdapter for MSBA and Populate the DataSet
myDA.SelectCommand = myCommand_msba
myDA.Fill(myDS)
'Create the DataAdapter for BCAM and Populate the DataSet
myDA.SelectCommand = myCommand_bcam
myDA.Fill(myDS)
'Create the DataAdapter for AFCA and Populate the DataSet
myDA.SelectCommand = myCommand_afca
myDA.Fill(myDS)
'Set the datagrid's datasource to the dataset and databind
dgAllCompanies.DataSource = myDS
dgAllCompanies.DataBind()
'Display error message if there are no records.
If myDS.Tables(0).Rows.Count = 0 Then
lblNoResults.Visible = True
dgAllCompanies.Visible = False
Else
lblNoResults.Visible = False
dgAllCompanies.Visible = True
End If
''*** Clean Up
myDS.Dispose()
myDS = Nothing
myDA.Dispose()
myDA = Nothing
myCommand_amfnat.Dispose()
myCommand_amfnat = Nothing
myCommand_msba.Dispose()
myCommand_msba = Nothing
myCommand_bcam.Dispose()
myCommand_bcam = Nothing
myCommand_afca.Dispose()
myCommand_afca = Nothing
End Sub
Thanks for taking the time to look at my problem!
Crjunkyou can create your own custom class and implement icomparable interface
, then use arraylist to bind data to datagrid
crjunk wrote:
> I have 4 different databases that I'm having to pull data from in order
> to populate a datagrid. I am able to do this, but my problem is that
> because I'm pulling the data from 4 different databases, the data is
> ordered alphabetically but is grouped by database.
> Here is an example of what is happening to the data in the datgrid with
> the code that I have now.
> DB1 Apple
> DB1 Bird
> DB1 Cake
> DB2 Airplane
> DB2 Boat
> DB2 Circle
> DB3 Amazing
> DB3 Blue
> etc....
> I want ALL the data in the datagrid ordered alphabetically, reguardless
> of which database it is from.
> This is the code that I'm using to bind data to my datagrid. Can I add
> something to my code to order the data correctly or do I need to go
> about this another way?
> Private Sub BindData()
> GetConnectionString()
> Dim strSQL As String = "SELECT DISTINCT DB_PDESCR, DB_PPROD
> FROM PUB.PCFPOLCY "
> Dim strWhere As String = ""
> Dim strOrderBy As String = ""
> Dim tmpID As String = Request.QueryString("ID")
> 'Ensure that the ID is 4 charactes long
> While Len(Trim(tmpID)) < 4
> tmpID = "0" & Trim(tmpID)
> End While
> strWhere = " WHERE DB_PPROD = '" & Trim(tmpID) & "'"
> strOrderBy = " ORDER BY DB_PDESCR"
> strSQL = strSQL & strWhere & strOrderBy
> Dim myDA As New OdbcDataAdapter
> Dim myDS As New DataSet
> Dim myCommand_amfnat As New OdbcCommand(strSQL,
> amfnat_OdbcConnection)
> Dim myCommand_msba As New OdbcCommand(strSQL,
> msba_OdbcConnection)
> Dim myCommand_bcam As New OdbcCommand(strSQL,
> bcam_OdbcConnection)
> Dim myCommand_afca As New OdbcCommand(strSQL,
> afca_OdbcConnection)
> 'Create the DataAdapter for AMFNAT and Populate the DataSet
> myDA.SelectCommand = myCommand_amfnat
> myDA.Fill(myDS)
> 'Create the DataAdapter for MSBA and Populate the DataSet
> myDA.SelectCommand = myCommand_msba
> myDA.Fill(myDS)
> 'Create the DataAdapter for BCAM and Populate the DataSet
> myDA.SelectCommand = myCommand_bcam
> myDA.Fill(myDS)
> 'Create the DataAdapter for AFCA and Populate the DataSet
> myDA.SelectCommand = myCommand_afca
> myDA.Fill(myDS)
> 'Set the datagrid's datasource to the dataset and databind
> dgAllCompanies.DataSource = myDS
> dgAllCompanies.DataBind()
> 'Display error message if there are no records.
> If myDS.Tables(0).Rows.Count = 0 Then
> lblNoResults.Visible = True
> dgAllCompanies.Visible = False
> Else
> lblNoResults.Visible = False
> dgAllCompanies.Visible = True
> End If
> ''*** Clean Up
> myDS.Dispose()
> myDS = Nothing
> myDA.Dispose()
> myDA = Nothing
> myCommand_amfnat.Dispose()
> myCommand_amfnat = Nothing
> myCommand_msba.Dispose()
> myCommand_msba = Nothing
> myCommand_bcam.Dispose()
> myCommand_bcam = Nothing
> myCommand_afca.Dispose()
> myCommand_afca = Nothing
> End Sub
>
> Thanks for taking the time to look at my problem!
> Crjunk
>
Thanks Elton and ashish. I figured out that I could use a DataView
before I read your message after doing a bunch of searching. Thanks
for your help. Here is what I added/changed in my code.
'Create a DataView so that I can order the data before the
DataGrid is populated.
'Otherwise the data will be in alphabetical order in DataGrid,
but grouped by DataBase.
Dim dvArrange As DataView = myDS.Tables(0).DefaultView
dvArrange.Sort = "DB_PDESCR"
'Set the datagrid's datasource to the DataView and bind data.
dgAllCompanies.DataSource = dvArrange
dgAllCompanies.DataBind()

populate a dg column based upon the value populated to another row in the datagrid

Is it possible when populating a datagrid to populate a dropdownlist
column based upon the value populated to another row in the datagrid?
(i.e. I have a drop down which I want to populate differently for each
row with user names based upon a UserRegionID which is also a column in
the row).
Since you don't actually know the value of the UserRegionID until the
data is already bound to the datagrid, how do you do this?
Thanks,
Mike
*** Sent via Developersdex http://www.examnotes.net ***You can use the datagrid events (RowDataBound I think) to handle this
by populating your dropdown using the id of each row as the grid is
populated
HTH
---
David Gray
ASP.NET/C# Developer/Architect (MCAD.NET)
On Fri, 13 Jan 2006 02:23:16 -0800, Mike P <mike.parr@.gmail.com>
wrote:

>Is it possible when populating a datagrid to populate a dropdownlist
>column based upon the value populated to another row in the datagrid?
>(i.e. I have a drop down which I want to populate differently for each
>row with user names based upon a UserRegionID which is also a column in
>the row).
>Since you don't actually know the value of the UserRegionID until the
>data is already bound to the datagrid, how do you do this?
>
>Thanks,
>Mike
>
>*** Sent via Developersdex http://www.examnotes.net ***

populate a dg column based upon the value populated to another row in the datagrid

Is it possible when populating a datagrid to populate a dropdownlist
column based upon the value populated to another row in the datagrid?
(i.e. I have a drop down which I want to populate differently for each
row with user names based upon a UserRegionID which is also a column in
the row).

Since you don't actually know the value of the UserRegionID until the
data is already bound to the datagrid, how do you do this?

Thanks,

Mike

*** Sent via Developersdex http://www.developersdex.com ***You can use the datagrid events (RowDataBound I think) to handle this
by populating your dropdown using the id of each row as the grid is
populated

HTH

-------------
David Gray
ASP.NET/C# Developer/Architect (MCAD.NET)

On Fri, 13 Jan 2006 02:23:16 -0800, Mike P <mike.parr@.gmail.com>
wrote:

>Is it possible when populating a datagrid to populate a dropdownlist
>column based upon the value populated to another row in the datagrid?
>(i.e. I have a drop down which I want to populate differently for each
>row with user names based upon a UserRegionID which is also a column in
>the row).
>Since you don't actually know the value of the UserRegionID until the
>data is already bound to the datagrid, how do you do this?
>
>Thanks,
>Mike
>
>*** Sent via Developersdex http://www.developersdex.com ***

Populate dataGrid

I would like to have 24 rows (one for each hour - from 0 to 24h).
Than I have some meetings at some hour and different subjects for each
meeting.

So I should have 24 rows, and if there is some meeting at some hour, there
should be displayed that meeting with all subjects in one cell.

I can get data from database in order like that:

hour meeting subject

9 meeting1 subject1
9 meeting1 subject2
9 meeting1 subject3
10 meeting2 subject1

....and so on

My cell should be displayed like this (for hour 9 for example):

| 9 meeting1
| subject1
| subject2
| subject3
_____________
|10 meeting2
| subject1

Every meeting and subjects displayed are links to the page with subject or
meeting.
What should I use? Can I use data grid? If i populate it with my sql data
then I get more than 24 rows.

Is there some idea?

Thank you,
SimonYou can but you will need to do some editing by hand.

To get things in the right format before using the data in the grid.

"simon" <simon.zupan@.stud-moderna.si> wrote in message
news:u5z3t4OtDHA.1060@.TK2MSFTNGP12.phx.gbl...
> I would like to have 24 rows (one for each hour - from 0 to 24h).
> Than I have some meetings at some hour and different subjects for each
> meeting.
> So I should have 24 rows, and if there is some meeting at some hour, there
> should be displayed that meeting with all subjects in one cell.
> I can get data from database in order like that:
> hour meeting subject
> 9 meeting1 subject1
> 9 meeting1 subject2
> 9 meeting1 subject3
> 10 meeting2 subject1
> ...and so on
> My cell should be displayed like this (for hour 9 for example):
> | 9 meeting1
> | subject1
> | subject2
> | subject3
> _____________
> |10 meeting2
> | subject1
> Every meeting and subjects displayed are links to the page with subject or
> meeting.
> What should I use? Can I use data grid? If i populate it with my sql data
> then I get more than 24 rows.
> Is there some idea?
> Thank you,
> Simon
How do you mean to get things in the right format?
Change sql query or check each row in datagrid when creating and move to the
next row if the row for hour 9 for example was already created (that way I
would probably get 24 rows I needed, but still I should design cell
somehow)?

Do you have some example?

Thank you for your answer,
Simon

"Aemca" <Aemca@.none.com> wrote in message
news:OLbI6CPtDHA.2088@.TK2MSFTNGP09.phx.gbl...
> You can but you will need to do some editing by hand.
> To get things in the right format before using the data in the grid.
>
>
> "simon" <simon.zupan@.stud-moderna.si> wrote in message
> news:u5z3t4OtDHA.1060@.TK2MSFTNGP12.phx.gbl...
> > I would like to have 24 rows (one for each hour - from 0 to 24h).
> > Than I have some meetings at some hour and different subjects for each
> > meeting.
> > So I should have 24 rows, and if there is some meeting at some hour,
there
> > should be displayed that meeting with all subjects in one cell.
> > I can get data from database in order like that:
> > hour meeting subject
> > 9 meeting1 subject1
> > 9 meeting1 subject2
> > 9 meeting1 subject3
> > 10 meeting2 subject1
> > ...and so on
> > My cell should be displayed like this (for hour 9 for example):
> > | 9 meeting1
> > | subject1
> > | subject2
> > | subject3
> > _____________
> > |10 meeting2
> > | subject1
> > Every meeting and subjects displayed are links to the page with subject
or
> > meeting.
> > What should I use? Can I use data grid? If i populate it with my sql
data
> > then I get more than 24 rows.
> > Is there some idea?
> > Thank you,
> > Simon

populate datagrid

Hello,

Here is the part of my code, I need to add a datagrid and populate is from
this sql string. Can you write the rest of the code?

Dim Da As New OdbcDataAdapter
Dim Ds As New DataSet
Dim cmdSelect As New OdbcCommand

cmdSelect = Conn.CreateCommand
cmdSelect.CommandText = "SELECT * FROM myTable"

Thanks,
Jim.Hope this helps;
<code
/* ### In Web.config BEGIN ### */
<configuration
<appSettings>
<add key="IntranetConnStr_Core" value="Data
Source=<DBServerName_Here>;user
id=<UserID_Here>;password=<Password_Here>;initial catalog=<DB_Here>" />
</appSettings
/* ### In Web.config END ### */

/** Calling code BEGIN **/
Dim dvEventStatuss As New DataView
'Note! strSQLToRun = I read the SQL CMD in from a XLM file.
dvEventStatuss = Do_Get.Do_DBConnection("TBL_EventStatuss", strSQLToRun,
ConfigurationSettings.AppSettings(strConnStr), (strWhoCalledMe &
".Do_DBGridInit"), objVisitor)
With uwgOrderEventStatuss
.DataSource = dvEventStatuss
.DataBind()
end with
/** Calling code BEGIN **/

Public Function Do_DBConnection(ByVal strTBLName As String, ByVal strSQL As
String, ByVal strConnStrToUse As String, ByVal strWhoCalledMe As String,
ByVal objVisitor As clsSiteFunctions.clsUser) As DataView
Dim dvDataView As New DataView
Dim dsDataSet As New DataSet
Dim Connection As New SqlConnection

Try
strConnStrToUse = "IntranetConnStr_Core"
strSQL = "Select * FROM <TableName_Here>"
strTBLName = "TBL_TableName"

Connection.ConnectionString =
ConfigurationSettings.AppSettings(strConnStrToUse)
Dim Adapter As New SqlDataAdapter(strSQL, Connection)
Adapter.Fill(dsDataSet, strTBLName)
Connection.Open()
dvDataView.Table = dsDataSet.Tables(strTBLName)
Adapter.Dispose()
Connection.Close()
Connection.Dispose()
Catch

End Try
Do_DBConnection = dvDataView
End Function

</code
"JIM.H." wrote:

> Hello,
> Here is the part of my code, I need to add a datagrid and populate is from
> this sql string. Can you write the rest of the code?
> Dim Da As New OdbcDataAdapter
> Dim Ds As New DataSet
> Dim cmdSelect As New OdbcCommand
> cmdSelect = Conn.CreateCommand
> cmdSelect.CommandText = "SELECT * FROM myTable"
>
> Thanks,
> Jim.

populate datagrid

Hello,
Here is the part of my code, I need to add a datagrid and populate is from
this sql string. Can you write the rest of the code?
Dim Da As New OdbcDataAdapter
Dim Ds As New DataSet
Dim cmdSelect As New OdbcCommand
cmdSelect = Conn.CreateCommand
cmdSelect.CommandText = "SELECT * FROM myTable"
Thanks,
Jim.Hope this helps;
<code>
/* ### In Web.config BEGIN ### */
<configuration>
<appSettings>
<add key="IntranetConnStr_Core" value="Data
Source=<DBServerName_Here>;user
id=<UserID_Here>;password=<Password_Here>;initial catalog=<DB_Here>" />
</appSettings>
/* ### In Web.config END ### */
/** Calling code BEGIN **/
Dim dvEventStatuss As New DataView
'Note! strSQLToRun = I read the SQL CMD in from a XLM file.
dvEventStatuss = Do_Get.Do_DBConnection("TBL_EventStatuss", strSQLToRun,
ConfigurationSettings.AppSettings(strConnStr), (strWhoCalledMe &
".Do_DBGridInit"), objVisitor)
With uwgOrderEventStatuss
.DataSource = dvEventStatuss
.DataBind()
end with
/** Calling code BEGIN **/
Public Function Do_DBConnection(ByVal strTBLName As String, ByVal strSQL As
String, ByVal strConnStrToUse As String, ByVal strWhoCalledMe As String,
ByVal objVisitor As clsSiteFunctions.clsUser) As DataView
Dim dvDataView As New DataView
Dim dsDataSet As New DataSet
Dim Connection As New SqlConnection
Try
strConnStrToUse = "IntranetConnStr_Core"
strSQL = "Select * FROM <TableName_Here>"
strTBLName = "TBL_TableName"
Connection.ConnectionString =
ConfigurationSettings.AppSettings(strConnStrToUse)
Dim Adapter As New SqlDataAdapter(strSQL, Connection)
Adapter.Fill(dsDataSet, strTBLName)
Connection.Open()
dvDataView.Table = dsDataSet.Tables(strTBLName)
Adapter.Dispose()
Connection.Close()
Connection.Dispose()
Catch
End Try
Do_DBConnection = dvDataView
End Function
</code>
"JIM.H." wrote:

> Hello,
> Here is the part of my code, I need to add a datagrid and populate is from
> this sql string. Can you write the rest of the code?
> Dim Da As New OdbcDataAdapter
> Dim Ds As New DataSet
> Dim cmdSelect As New OdbcCommand
> cmdSelect = Conn.CreateCommand
> cmdSelect.CommandText = "SELECT * FROM myTable"
>
> Thanks,
> Jim.
>

populate datagrid from listbox value

I have to populate a list box from a db table and when the user clicks on
the value in the listbox I need to then populate a datagrid with detailed
information for the highlighted row.
How can i do that?Try this?
ASP.NET: Master/Detail View using a DropDownList and a DataGrid
[url]http://authors.aspalliance.com/aldotnet/examples/masterdetail_ddl_datagrid.aspx[/u
rl]
"Mike" <me@.me.com> wrote in message
news:ORHOgJWXEHA.2364@.TK2MSFTNGP12.phx.gbl...
>I have to populate a list box from a db table and when the user clicks on
> the value in the listbox I need to then populate a datagrid with detailed
> information for the highlighted row.
> How can i do that?
>

populate datagrid from listbox value

I have to populate a list box from a db table and when the user clicks on
the value in the listbox I need to then populate a datagrid with detailed
information for the highlighted row.

How can i do that?Try this?

ASP.NET: Master/Detail View using a DropDownList and a DataGrid

http://authors.aspalliance.com/aldo...l_datagrid.aspx

"Mike" <me@.me.com> wrote in message
news:ORHOgJWXEHA.2364@.TK2MSFTNGP12.phx.gbl...
>I have to populate a list box from a db table and when the user clicks on
> the value in the listbox I need to then populate a datagrid with detailed
> information for the highlighted row.
> How can i do that?

Populate DataGrid from dynamic DropDown

Wow, it really sucks when you are trying to learn something and it just seems to not want to come together!

Anyways, my problem is this: I have a couple DropDownLists that are being populated from a database. Once the page loads, I am trying to set it up where the user can select an item from the DropDown, and then using a value associated the item in the DropDown, search the database again, and pull all matching records and place them in a DataGrid.

My code looks something like this:


<script runat="server"
Sub Page_Load(Source As Object, E As EventArgs)
If Not Page.IsPostBack Then
StatesDropDownList()
End IF
End Sub

Sub StatesDropDownList()

Dim strConnection As String = "Provider=Microsoft.Jet.OleDb.4.0;data source=" & Server.Mappath("\data\globalresorts.mdb")
Dim objConnection As New OleDbConnection (strConnection)
Dim strSqlStates As String = "SELECT DISTINCT State FROM Properties"

Dim objCommand As New OleDbCommand(strSqlStates, objConnection)
Dim objReader As OleDbDataReader = Nothing

objConnection.Open()
objReader = objCommand.ExecuteReader()

ddlStatesFilter.DataSource = objReader
ddlStatesFilter.DataTextField = "State"
ddlStatesFilter.DataValueField = "State"
ddlStatesFilter.DataBind()
objConnection.Close()
Dim DefaultState As ListItem = New ListItem
DefaultState.Text = "Select a State"
DefaultState.Value = "0"
ddlStatesFilter.Items.Insert(0, DefaultState)

End Sub

Sub DoSearch(Source as Object, E as EventArgs)

Dim strStates As String = ddlStatesFilter.SelectedItem.Value
Dim strConnection As String = "Provider=Microsoft.Jet.OleDb.4.0;data source=" & Server.Mappath("\data\globalresorts.mdb")
Dim objConnection As New OleDbConnection(strConnection)
Dim strSQL As String = "SELECT * FROM Properties WHERE State =" & ddlStatesFilter.SelectedItem.Value & " ORDER BY ID"

Dim objAdapter as New OleDbDataAdapter(strSQL, objConnection)

Dim objDataSet As New DataSet()
objAdapter.Fill(objDataSet, "dtProperties")

dgProperties.PagerStyle.NextPageText = "Next"
dgProperties.PagerStyle.PrevPageText = "Previous"

dgProperties.DataSource = objDataSet.Tables.Item("dtProperties")
dgProperties.DataBind()

End Sub
</script>

And then the control and the DataGrid look a little something like this:


<form runat="server>
<asp:literal ID="lbStatesFilter" runat="server" Text="State: " />
<asp:dropdownlist ID="ddlStatesFilter" runat="server" Font-Names="Verdana" Font-Size="8pt" />
<asp:button ID="SubmitSearch" runat="server" OnClick="DoSearch" Text="Search Listings" Font-Names="Verdana" Font-Size="8pt" Width="150" />
<asp:Datagrid id="dgProperties" runat="server"
AutoGenerateColumns="false"
Font-Size="8pt"
CellPadding="8"
AlternatingItemStyle-BackColor="#CCCCCC"
Font-Names="Verdana"
Width="100%"
AllowPaging="True"
OnPageIndexChanged="GridPageChange"
PageSize="20">
<HeaderStyle font-bold="True" forecolor="White" backcolor="#005BAC"></HeaderStyle>
<EditItemStyle backcolor="WhiteSmoke"></EditItemStyle>
<AlternatingItemStyle backcolor="Gainsboro"></AlternatingItemStyle>
<ItemStyle backcolor="WhiteSmoke"></ItemStyle>
<Columns>
<asp:BoundColumn DataField="ID" HeaderText="ID" DataFormatString="{0:N0}" />
<asp:hyperlinkcolumn HeaderText="Resort Name" datanavigateurlfield="ID" datanavigateurlformatstring="details.aspx?id={0}" datatextfield="Resort_Name" />
<asp:BoundColumn DataField="City" HeaderText="City" />
<asp:BoundColumn DataField="State" HeaderText="State" />
<asp:BoundColumn DataField="Bedrooms" HeaderText="Bedrooms" />
<asp:BoundColumn DataField="Week" HeaderText="Week" />
<asp:BoundColumn DataField="Sale_Price" HeaderText="Sale Price" DataFormatString="{0:c2}" />
<asp:BoundColumn DataField="Rent_Price" HeaderText="Rent Price" DataFormatString="{0:c2}" />
</Columns>
</asp:Datagrid>
</form>

And here is the error that I am getting when I try and run it:


Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.OleDb.OleDbException: No value given for one or more required parameters.

Source Error:

Line 149:
Line 150: Dim objDataSet As New DataSet()
Line 151: objAdapter.Fill(objDataSet, "dtProperties")
Line 152:
Line 153:dgProperties.PagerStyle.NextPageText = "Next"

Source File: D:\...\search.aspx Line: 151

Thanks in advance for any help on this one. And sorry for so much code, but Im just not sure where the problem is coming from, so I want to make sure I give all the facts.

-JasonWithout looking at your code, basic concpets.
On page load, populate the drop down lists, enclose this in the If Page.IsPostBack = False, so it only happens once, obviously this can change based on your requirements.
Next, have a method that populates the datagrid, such as the dropdownlist selectedindexchange. Just use the selectedindex, value to hit the database to populate the datagrid.

Populate datagrid from XML file using where type query

I am able to populate a datagrid from an XML variable using the
following:
Try
Dim ds As New DataSet
ds.ReadXml(New
StringReader(HttpContext.Current.Application("var").ToString))
dataMeet.DataSource = ds
dataMeet.DataBind()
Catch ex As Exception
error_email.fncErrorHandler(ex)
lblError.Text = ex.ToString
End Try
however this does not allow me to use a sql type query to select
exactly the data I want in the datagrid.
The query I am looking to achieve is actually very simple, just a
simple 'where' but I have no idea how to achieve this when binding to
an xml variable
The sql query and a sample xml file are pasted below:
select TITLE, FIRST_NAME || ' ' || LAST_NAME AS FULL_NAME, DEPT, EMAIL,
PHONE FROM DATABASE.TABLE "
WHERE MEMBERTYPE_CODE = 'MEM' ORDER BY MEMBER_ID
<NewDataSet>
<Table>
<MEMBERTYPE_CODE>OFF</MEMBERTYPE_CODE>
<LAST_NAME>Smith</LAST_NAME>
<FIRST_NAME>Harry</FIRST_NAME>
<TITLE>engineer</TITLE>
<DEPT>engineering</DEPT>
<EMAIL>harry.smith@dotnet.itags.org.email.address</EMAIL>
<PHONE>(111) 111-1111</PHONE>
</Table>
<Table>
<MEMBERTYPE_CODE>MEM</MEMBERTYPE_CODE>
<LAST_NAME>fred</LAST_NAME>
<FIRST_NAME>bloggs</FIRST_NAME>
<TITLE>Webmaster</TITLE>
<DEPT>Information Technology Services</DEPT>
<EMAIL>fred.blogs@dotnet.itags.org.email.address</EMAIL>
<PHONE>(111) 111-1112</PHONE>
</Table>
</NewDataSet>
Thank you for your timePerfect, just what I needed!
Thank you

Populate datagrid from XML file using where type query

I am able to populate a datagrid from an XML variable using the
following:

Try
Dim ds As New DataSet
ds.ReadXml(New
StringReader(HttpContext.Current.Application("var").ToString))
dataMeet.DataSource = ds
dataMeet.DataBind()
Catch ex As Exception
error_email.fncErrorHandler(ex)
lblError.Text = ex.ToString
End Try

however this does not allow me to use a sql type query to select
exactly the data I want in the datagrid.

The query I am looking to achieve is actually very simple, just a
simple 'where' but I have no idea how to achieve this when binding to
an xml variable

The sql query and a sample xml file are pasted below:

select TITLE, FIRST_NAME || ' ' || LAST_NAME AS FULL_NAME, DEPT, EMAIL,
PHONE FROM DATABASE.TABLE "
WHERE MEMBERTYPE_CODE = 'MEM' ORDER BY MEMBER_ID

<NewDataSet>
<Table>
<MEMBERTYPE_CODE>OFF</MEMBERTYPE_CODE>
<LAST_NAME>Smith</LAST_NAME>
<FIRST_NAME>Harry</FIRST_NAME>
<TITLE>engineer</TITLE>
<DEPT>engineering</DEPT>
<EMAIL>harry.smith@dotnet.itags.org.email.address</EMAIL>
<PHONE>(111) 111-1111</PHONE>
</Table>
<Table>
<MEMBERTYPE_CODE>MEM</MEMBERTYPE_CODE>
<LAST_NAME>fred</LAST_NAME>
<FIRST_NAME>bloggs</FIRST_NAME>
<TITLE>Webmaster</TITLE>
<DEPT>Information Technology Services</DEPT>
<EMAIL>fred.blogs@dotnet.itags.org.email.address</EMAIL>
<PHONE>(111) 111-1112</PHONE>
</Table>
</NewDataSet
Thank you for your timeHi gn,

You can use DataView's properties RowFilter and Sort to
perform functionality similar to 'WHERE' condition
and 'ORDER BY' in sql query. Following is sample code
snippet:

Dim dv As DataView = ds.Tables(0).DefaultView
dv.RowFilter = "MEMBERTYPE_CODE = 'MEM'"
dv.Sort = "LAST_NAME"
dataMeet.DataSource = dv
dataMeet.DataBind()

HTH

Elton Wang
elton_wang@.hotmail.com

>--Original Message--
>I am able to populate a datagrid from an XML variable
using the
>following:
> Try
> Dim ds As New DataSet
> ds.ReadXml(New
>StringReader(HttpContext.Current.Application
("var").ToString))
> dataMeet.DataSource = ds
> dataMeet.DataBind()
> Catch ex As Exception
> error_email.fncErrorHandler(ex)
> lblError.Text = ex.ToString
> End Try
>however this does not allow me to use a sql type query to
select
>exactly the data I want in the datagrid.
>The query I am looking to achieve is actually very
simple, just a
>simple 'where' but I have no idea how to achieve this
when binding to
>an xml variable
>The sql query and a sample xml file are pasted below:
>select TITLE, FIRST_NAME || ' ' || LAST_NAME AS
FULL_NAME, DEPT, EMAIL,
>PHONE FROM DATABASE.TABLE "
>WHERE MEMBERTYPE_CODE = 'MEM' ORDER BY MEMBER_ID
><NewDataSet>
> <Table>
> <MEMBERTYPE_CODE>OFF</MEMBERTYPE_CODE>
> <LAST_NAME>Smith</LAST_NAME>
> <FIRST_NAME>Harry</FIRST_NAME>
> <TITLE>engineer</TITLE>
> <DEPT>engineering</DEPT>
> <EMAIL>harry.smith@.email.address</EMAIL>
> <PHONE>(111) 111-1111</PHONE>
> </Table>
> <Table>
> <MEMBERTYPE_CODE>MEM</MEMBERTYPE_CODE>
> <LAST_NAME>fred</LAST_NAME>
> <FIRST_NAME>bloggs</FIRST_NAME>
> <TITLE>Webmaster</TITLE>
> <DEPT>Information Technology Services</DEPT>
> <EMAIL>fred.blogs@.email.address</EMAIL>
> <PHONE>(111) 111-1112</PHONE>
> </Table>
></NewDataSet>
>Thank you for your time
>.
Perfect, just what I needed!

Thank you

Saturday, March 24, 2012

Populate dropdown

Hy Guys,

I have a datagrid that, in the edititem mode, have a dropdownlist. This
dropdownlist have to be populated with the items of another dropdownlist
that is in the same page.

How can I do it??

Thank'sthis is what you need

http://msdn.microsoft.com/library/d...stomcolumns.asp

--
Regards,

HD

"Andr Almeida Maldonado" <deweb@.bol.com.br> wrote in message
news:ebVFaqi2DHA.2428@.tk2msftngp13.phx.gbl...
> Hy Guys,
> I have a datagrid that, in the edititem mode, have a dropdownlist. This
> dropdownlist have to be populated with the items of another dropdownlist
> that is in the same page.
> How can I do it??
> Thank's

populate dropdownlist in datagrid

Really struggline with how to populate a dropdownlist in a datagrid when i click the edit link:

Sub dgrdResults_PageIndexChanged (s as Object, e as DataGridPageChangedEventArgs)
dgrdResults.CurrentPageIndex = e.NewPageIndex
BindDataGrid
End Sub

Sub dgrdResults_CancelCommand(s as Object, e as DataGridCommandEventArgs)
dgrdResults.EditItemIndex = -1
BindDataGrid
End Sub

Sub dgrdResults_UpdateCommand(s as Object, e as DataGridCommandEventArgs)
Dim TempList as DropDownList
Dim TempValue as String

TempList = e.Item.FindControl("drpUnitRating")
TempValue = TempList.SelectedItem.Value

dgrdResults.EditItemIndex = -1
BindDataGrid
End Sub

Function BindRating()
'Dim colArrayList as New ArrayList
'colArrayList.Add("5")
'colArrayList.Add("4")
'colArrayList.Add("3")
'colArrayList.Add("2")
'colArrayList.Add("1")
'drpUnitRating.DataSource = colArrayList
'drpUnitRating.DataBind()
End Function

Sub dgrdResults_EditCommand(s as Object, e as DataGridCommandEventArgs)
dgrdResults.EditItemIndex = e.Item.ItemIndex
BindDataGrid
End Sub

.....

<asp:DataGrid
ID="dgrdResults"
AllowPaging="true"
AutoGenerateColumns="false"
PagerStyle-Mode="NumericPages" PagerStyle-PageButtonCount="5" PagerStyle-Position="Bottom"
PageSize="25"
OnPageIndexChanged="dgrdResults_PageIndexChanged"
OnEditCommand="dgrdResults_EditCommand"
OnUpdateCommand="dgrdResults_UpdateCommand"
OnCancelCommand="dgrdResults_CancelCommand"
CellPadding="0"
BorderWidth="0"
GridLines="None" CssClass="../fmcss.css"
runat="server" >
<columns>
<asp:TemplateColumn>
<itemTemplate>
<%# Container.DataItem("PRD_BRAND") %> <%# Container.DataItem("PRD_MODEL") %> <%# Container.DataItem("PRD_NAME") %> <%# Container.DataItem("PRD_CATEGORY_CD") %>
</itemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn>
<itemTemplate>
<%# Container.DataItem("UNIT_RATING") %>
</itemTemplate>
<edititemtemplate>
<asp:DropDownList ID="drpUnitRating" DataTextField='<%# Container.DataItem("UNIT_RATING") %>' DataValueField='<%# Container.DataItem("UNIT_RATING") %>' DataSource='<%# BindRating %>' runat="server"></asp:DropDownList>
</edititemtemplate>
</asp:TemplateColumn>
<asp:EditCommandColumn EditText="E" UpdateText="U" CancelText="C" />
</columns>
</asp:DataGrid>

I can do it either by connecting to a database or by just typing in say 5 values 1-5. I will be doing it both ways once I figure out how to do this. Right now I am just trying to just do it without the connecting to a database.

Thanks in advance to any replies.try this link:

http://aspnet.4guysfromrolla.com/articles/051904-1.aspx

hth,
Kev
Kevin,

Nice link.

Anyone know how to translate this to vb.net?

private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
// see if we are working with the row being edited
if (e.Item.ItemType == ListItemType.EditItem)
{
// populate the division DDL
DropDownList ddlDivision = (DropDownList) e.Item.FindControl("ddlDivision");

// connect to Access DB
OleDbConnection myConnection = new OleDbConnection(ConfigurationSettings.AppSettings["connString"]);
myConnection.Open();

const string SQL = @."SELECT DivisionID, Name FROM Divisions ORDER BY Name";
OleDbCommand myCommand = new OleDbCommand(SQL, myConnection);

ddlDivision.DataSource = myCommand.ExecuteReader();
ddlDivision.DataBind();

myConnection.Close();

// now, select the appropriate division
int currentDivisionID = Convert.ToInt32(DataBinder.Eval(e.Item.DataItem, "DivisionID"));
ListItem li = ddlDivision.Items.FindByValue(currentDivisionID.ToString());
if (li != null) li.Selected = true;

// finally, populate the department DDL based on the selected division
int currentDepartmentID = Convert.ToInt32(DataBinder.Eval(e.Item.DataItem, "DepartmentID"));
if (li != null) li.Selected = true;

DropDownList ddlDepartment = (DropDownList) e.Item.FindControl("ddlDepartment");

PopulateDepartmentBasedOnDivision(ddlDepartment, ddlDivision, currentDepartmentID);
}
}

populate my datagrid RESOLVED

im trying to fill my datagrid but when the page loads in the browser you cant even see it.
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... :)

populate one dropdownlist based on the selected of another dropdownlist

hi
i am using c# asp.net
i have one datagrid in my form and i bound two dropdown list using coding. i loaded my database values in my first dropdown list by using this code:

private void Page_Load(object sender, System.EventArgs e)
{// Put user code to initialize the page here
if(!Page.IsPostBack)
{ BindData();
PopulateList();
}
}
public void BindData()
{
SqlDataAdapter ad = new SqlDataAdapter("SELECT Course_NAME FROM JTSISControlManager_Course",conn);
DataSet ds = new DataSet();
ad.Fill(ds,"JTSISControlManager_Course");
DataGrid2.DataSource = ds;
DataGrid2.DataBind();

}
public DataSet PopulateList()
{

SqlDataAdapter ad = new
SqlDataAdapter("SELECT Course_Name FROM JTSISControlManager_Course", conn);

DataSet ds = new DataSet();
ad.Fill(ds,"JTSISControlManager_Course");
return ds;
}

here is the html coding:

<form id="Form1" method="post" runat="server">
<asp:datagrid id="DataGrid2" style="Z-INDEX: 101; LEFT: 328px; POSITION: absolute; TOP: 64px"
runat="server" Width="408px" AutoGenerateColumns="False" DataKeyField="Course_NAME">
<Columns>
<asp:BoundColumn DataField="Course_NAME" HeaderText="Course_NAME" />
<asp:TemplateColumn>
<HeaderTemplate>
<aspropDownList ID="Dropdownlist1" Runat="server" DataTextField="Course_NAME" OnSelectedIndexChanged ="DropDown_SelectedIndexChanged" DataSource =" <%#PopulateList()%> " AutoPostBack="True" />
<aspropDownList ID="Dropdownlist3" Runat="server" DataTextField="Dept_NAME" AutoPostBack="True" />
</HeaderTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid></form>

then using the following code i retreived my first dropdownlist value

protected void DropDown_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList list = (DropDownList)sender;
li=list.SelectedValue.Trim();
Response.Write(li);

}

my need is i want to use the retreived value of the first dropdownlist in query and fill the values in my second dropdownlist of the datagrid.
tell me how to use that retreived value of first dropdown list in next qurey and how to fill the second dropdownlist .so please help me to do this. give example coding to do my requirement
Edit/Delete MessageHi karthikeyan,

In my application I've Make and Model dropdowns. Model dropdown gets populated as soon as we select a make in a dropdown, it gets all the models for that make;

Here is my code;

Populating Model Dropdown
private void ddlMake_SelectedIndexChanged(object sender, System.EventArgs e)
{
if (ddlMake.SelectedValue != "")
{
PopulateFieldsInDropDowns("SELECT cat.DisplayText Model, to_char(cat.CATEGORYID) ModelID FROM TDCATEGORIES cat WHERE cat.CATEGORYLEVEL=4 and parentid= " + ddlMake.SelectedValue + " ORDER BY cat.DisplayText", ddlModel);
}
else
ddlModel.Items.Clear();
}

Populate Method
private void PopulateFieldsInDropDowns(string sqlQuery, DropDownList drpList)
{
try {
conn.Open();
OleDbCommand cmCommand = new OleDbCommand(sqlQuery, conn);
OleDbDataReader dreader = cmCommand.ExecuteReader();

drpList.Items.Clear();
drpList.Items.Add(new ListItem("", ""));

while (dreader.Read())
{
drpList.Items.Add(new ListItem(dreader.GetString(0), dreader.GetString(1)));
}

dreader.Close();

if (dreader != null)
dreader = null;

if (cmCommand != null)
cmCommand.Dispose();
}
catch
{
drpList.Items.Clear();
lblMessage.ForeColor = System.Drawing.Color.Red;
lblMessage.Text = "Cannot Get Data: Cannot Get Required Data.";
}
conn.Close();
}

It should rock.

thanks,
hi ahmarshi,

i tried which u given, but i got error:
System.NullReferenceException: Object reference not set to an instance of an object.

my first dropdown name is DropDownList1 and second name is ddlmodel
i modified my coding like this:
protected void DropDown_SelectedIndexChanged(object sender, System.EventArgs e)
{
DropDownList list = (DropDownList)sender;
li=list.SelectedValue.Trim();
Response.Write(li);

if (li != "")
{
PopulateFieldsInDropDowns("SELECT Dept_NAME from JTSISControlManager_Department where Course_ID in (select Course_ID from JTSISControlManager_Course where Course_NAME= '" + li + "')", ddlmodel);
}
else
ddlmodel.Items.Clear();
}
private void PopulateFieldsInDropDowns(string sqlQuery, DropDownList drpList)
{
try
{
conn.Open();
SqlCommand cmd = new SqlCommand(sqlQuery, conn);
SqlDataReader dreader =cmd.ExecuteReader();


drpList.Items.Clear();
drpList.Items.Add(new ListItem("", ""));

while (dreader.Read())
{
drpList.Items.Add(new ListItem(dreader.GetString(0), dreader.GetString(1)));
}

dreader.Close();

if (dreader != null)
dreader = null;

if (cmd!= null)
cmd.Dispose();
}
catch
{
drpList.Items.Clear();
//lblMessage.ForeColor = System.Drawing.Color.Red;
Response.Write ( "Cannot Get Data: Cannot Get Required Data.");
}
conn.Close();
}

i kept break point and run this but while comming to
this line
private void PopulateFieldsInDropDowns(string sqlQuery, System.Web.UI.WebControls.DropDownList drpList)
in the drplist comes <undefined value>.
then after comming to this line
drpList.Items.Add(new ListItem("", ""));
it automatically goes to catch.please tell me and give sugestion to rectify this prooblem.

populate one dropdown list from another and then populate a datagrid.

And that's not even the half of it:eek2:

I am hoping someone can help me here, because this is a pretty big problem.

1) I am looking to populate a dropdown list on on a webform from SQL.

2) and then when someone selects an item from the first dropdown list the second dropdown list is enabled and also populated with its own data via sql query.

3)Then when the user selects an item in the second dropdownlist
a pop menu shows up with field showing the current selections the user has made . The user can click a button on this form to close it.

4)Upon the selection of both dropdown lists there is a datagrid on the main form also populated with a Sql query. All of the queries I mentioned are on the the same table.

5) Lastly on the form is a button. Upon clicking the button it opens a new page that shows two dropdownlists and textbox all populated with the same data
and there are two button on that form cancel and save.

Imports System.Data
Imports System.Data.SqlClient

Public Class WebForm2
Inherits System.Web.UI.Page
Dim objConnection As SqlConnection = New _
SqlConnection("server = MSS; database = chris ;user id = night; password = night")
Dim objDataAdapter As New SqlDataAdapter
Dim objDataSet = New DataSet

#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 DropDownList1 As System.Web.UI.WebControls.DropDownList
Protected WithEvents DropDownList2 As System.Web.UI.WebControls.DropDownList
Protected WithEvents Label1 As System.Web.UI.WebControls.Label
Protected WithEvents Label2 As System.Web.UI.WebControls.Label
Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox
Protected WithEvents Label3 As System.Web.UI.WebControls.Label
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
Protected WithEvents Button2 As System.Web.UI.WebControls.Button

'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

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
objDataAdapter.SelectCommand = New SqlCommand
objDataAdapter.SelectCommand.Connection = objConnection
objDataAdapter.SelectCommand.CommandText = _
"Select Category, Application, Issues, Solution from t_Extract"
objDataAdapter.SelectCommand.CommandType = CommandType.Text
objConnection.Open()
objDataAdapter.Fill(objDataSet, "t_Extract")

DropDownList1.DataSource = objDataSet
DropDownList1.DataBind()

objConnection.Close()
objDataAdapter = Nothing
objConnection = Nothing

End Sub

Private Sub DropDownList1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged

End Sub
End Class

the html looks like this:

<%@dotnet.itags.org. Page Language="vb" AutoEventWireup="false" Codebehind="WebForm1.aspx.vb" Inherits="Category2.WebForm1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:DropDownList id="DropDownList1" style="Z-INDEX: 101; LEFT: 120px; POSITION: absolute; TOP: 16px"
runat="server" Width="120px" Height="24px"></asp:DropDownList>
<asp:DropDownList id="DropDownList2" style="Z-INDEX: 102; LEFT: 384px; POSITION: absolute; TOP: 16px"
runat="server" Width="128px" Height="16px"></asp:DropDownList>
<asp:DataGrid id="DataGrid1" style="Z-INDEX: 103; LEFT: 48px; POSITION: absolute; TOP: 64px" runat="server"
Width="464px" Height="104px"></asp:DataGrid>
<asp:Label id="Label1" style="Z-INDEX: 104; LEFT: 40px; POSITION: absolute; TOP: 16px" runat="server"
Width="72px" Height="16px">Category</asp:Label>
<asp:Label id="Label2" style="Z-INDEX: 105; LEFT: 296px; POSITION: absolute; TOP: 16px" runat="server"
Width="72px" Height="24px">Application</asp:Label>
<asp:Button id="Button1" style="Z-INDEX: 106; LEFT: 64px; POSITION: absolute; TOP: 232px" runat="server"
Width="72px" Text="Add New"></asp:Button>
</form>
</body>
</HTML>I've had to do something similar. Ended up being pretty simple. The first drop down was visible by default, and it automatically filled with its' information. On SelectedIndexChanged, it fired a PostBack, and the second drop down was made visible, and it populated with a Select query based on the SelectedValue of the first drop down. On the SelectedIndexChanged of the second drop down, it posed back and the data grid was made visible using the SelectedValue of the second drop down. it basically comes down to a nice chain of events where the next can ONLY be fired by the previous. Hope the idea helps.
I have populated the first dropdown successfully. But the second dropdown list data is not appearing when I select a choice from the first list.

here is my code for the second list. Maybe I am missing something ?

Private Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged

Dim oConn As SqlConnection
Dim oComm As SqlCommand
Dim oReader As SqlDataReader
Dim sSQL As String
Dim sConn As String

sSQL = "SELECT Category,Application, Issues, Solution, AssignTo from T_Issues WHERE ID='" & DropDownList1.SelectedValue() & "'"
sConn = "Server=night;Database = chris;User ID = minutia;Password=minutia;"

oConn = New SqlConnection(sConn)
oConn.Open()

oComm = New SqlCommand(sSQL, oConn)
oReader = oComm.ExecuteReader()

DropDownList2.DataSource = oReader
DropDownList2.DataValueField = "Application"
DropDownList2.DataTextField = "Application"
DropDownList2.DataBind()
'DropDownList2.Items.Insert(0, "-Select-")

'DropDownList2.Enabled = True
End Sub
Are you doing a postback check on the page to ensure that DDL1 is not being re-filled everytime?
Are you doing a postback check on the page to ensure that DDL1 is not being re-filled everytime?

No I don't believe so I did a postback check in the page load event with the first dropdown list but not the second. So how would this logic be integrated in my existing code. Actually on second thought I did do a postback check:

If Not page.POSTBACK THEN
in between was the code you see above here and it went to the If not and then skipped down to the end because it never stepped through the code.

If Not Page.IsPostBack Then
DropDownList2.Enabled = True
Dim oConn As SqlConnection
Dim oComm As SqlCommand
Dim oReader As SqlDataReader
Dim sSQL As String
Dim sConn As String

sSQL = "SELECT Category,Application, Issues, Solution, AssignTo from T_Issues WHERE ID='" & DropDownList1.SelectedValue() & "'"
sConn = "Server=night;Database = chris;User ID = minutia;Password=minutia;"

oConn = New SqlConnection(sConn)
oConn.Open()

oComm = New SqlCommand(sSQL, oConn)
oReader = oComm.ExecuteReader()

DropDownList2.DataSource = oReader
DropDownList2.DataValueField = "Application"
DropDownList2.DataTextField = "Application"
DropDownList2.DataBind()
'DropDownList2.Items.Insert(0, "-Select-")
End If

END IF

oK i fixed it stepping through the code the autopostback property needed to be set to true in the first dropdown list and then for the second dropdown list since it picked up the firing of the postback the first time would need to say If page.Postback = true
But now I am getting the following error which I just resolved by changing selected value to selected index and now I need to reset the postback value to true in both lists afterwards.
Now I need to create a dialog box holding the choices in both lists and then this in turn when selected on populates the grid with the specific rowset I need to have there.
The question beyond this is how do I get my results to the next webform. Basically I have a button whcih calls another webform. The webform has two dropdownlists and a textbox all of which need to be populated with category, application and issues from the previous page.
I was looking up global variables... but how would this work from the way I am looking to use them.

In the btnclick event I have

Dim catch1 As String = CStr(Session("Category"))
Dim catch2 As String = CStr(Session("Application"))
Response.Redirect("Webform2.aspx")

and on the page load of the 2nd webform I have
Session("Category") = ""
Session("Application") = ""

do I set them equal to the dropdownlist.selecteditem.text()ToString ?
You set the session variables in the first form, read them in the second. There are also context variables you can use for the same purpose.