Showing posts with label populating. Show all posts
Showing posts with label populating. Show all posts

Monday, March 26, 2012

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 array from a dataset ?

Can someone point me to an example of populating an array from a dataset ?

This .net stuff is killing me.What are you trying to do in more detail? What goes in each element of the array? What about multiple tables?

Not that I'm a Datset fan but you have a lot more functionality with your data in a dataset than an array.

Populate data in ListBox for Multiple Selections (C#)

Hi there,
I am new in ASP.NET and wonder if somebody can help me with populating data in a ListBox from a database. Users should be able to choose multiple selections and pass the selected values for a search query. Please let me know if I miss anything.
Thanks a lot in advance!
// search.aspx
<asp:ListBox id="Community2" runat="server"></asp:ListBox>
//search.aspx.cs

if (!Community2.Items.FindByValue("-1").Selected)

{

for (int i=0 ; i<Community2.Items.Count ; i++)

{

if (Community2.ItemsIdea [I].Selected)

{

if (Community2 != "") Community2 += ",";

Community2 += Community2.ItemsIdea [I].Value;

}

}

}


//db.cs

publicvoid PopulateCommunities2(ListControl i_list,bool i_showalloption)

{

OleDbDataAdapter adapter =new OleDbDataAdapter("SELECT distinct community FROM properties", m_conn);

DataTable dt =new DataTable();

adapter.Fill(dt);

i_list.Items.Clear();

if (i_showalloption) i_list.Items.Add(new ListItem("All Communities", "-1"));

for (int i=0 ; i<dt.Rows.Count ; i++)

{

i_list.Items.Add(new ListItem(dt.RowsIdea [I]["community"])); //I am using pre-build code and have no idea what else I could do here.

}

}

For databind of a ListBox, you don't need to use loop to put data into the list. Just use ListBox1.DataSource field. For example:
ListBox1.DataSourse = GetCommunities();
ListBox1.DataValueField = "community";
ListBox1.DataTextField = "community";
ListBox1.DataBind;
GetCommunites method could be a DataSet, DataTable or DataView like:
Private DataTable GetCommunities()
{

OleDbDataAdapter adapter =new OleDbDataAdapter("SELECT distinct community FROM properties", m_conn);

DataTable dt =new DataTable();

adapter.Fill(dt);


return dt;
}

For your process of the user selected items from the ListBox, you can put a "," at the first or last. But, after that, you need to remove the first "," (if you put at first), or remove the last "," (if you put at the last).


Also, you're treating Community2 like a listbox, as in
Community2.Items.FindByValue("-1")
...but you're also treating it as a string, like this:
Community2 += ",";
...sometimes even in the same statement!

if (Community2 != "") Community2 += ",";

Community2 += Community2.Items[i ].Value;

}
You need to decide which one it is (I'm assuming the former).

Saturday, March 24, 2012

Populate DropDown with dataview

I have a bunch of dropdown on my form and I am trying to optimize the populating process. I am filling a dataview with a store proc and pass the dataview to each dropdown's datasource with a filter and sort expression. Until then every thing is fine however I need to add a black row at the top of each drop down and I dont know how to add it to my dataview or directly to dropdown. Any help would be great.

Here is what I got up to now


fctFillDropDownList(ddSource, 30, strSortAsc, dvTemp)
...

'*************************************************************************
'*************************************************************************
Private Sub fctFillDropDownList(ByRef objControl As System.Web.UI.WebControls.DropDownList, _
ByVal iParentID As Int16, ByVal strSort As String, ByRef dvTemp As DataView)
'*************************************************************************
dvTemp.RowFilter = "parentId=" & iParentID
dvTemp.Sort = strSort
objControl.DataSource = dvTemp
objControl.DataTextField = "Texte"
objControl.DataValueField = "Texte"
End Sub

After you call DataBind on the dropdownlist, you can do this (C# syntax):

MyDropDownList.Items.Insert(0, new ListItem("", ""));

That will add a blank row at the beginning of the dropdownlist.

HTH
Thanks that worked

Populate dropdownlist...

I have a problem populating a dropdownlist with data from a dataset. Here is the code:

string strConnection="user id=logger;password=logger;";
strConnection+="database=MVS;server=4647117000N26";
SqlConnection objSqlConnection = new SqlConnection(strConnection);
objSqlConnection.Open();
DataSet objDataSet = new DataSet();
string strOrderDetails = "SELECT DISTINCT [job_name] FROM [mvs_jobs]";
SqlCommand objOrdDetailCommand = new SqlCommand(strOrderDetails,objSqlConnection);

SqlDataAdapter objODAdapter = new SqlDataAdapter(objOrdDetailCommand);






objODAdapter.Fill(objDataSet);
DropDownList1.DataSource = objDataSet;
DropDownList1.DataBind();
objSqlConnection.Close();

I am not really sure what the problem is, the dropdownbox is populated with "System.Data.DataRowView"...!?!

anyone who can help?
kind regards
Henrik...maybe you need to set the datamember property for the drop down list...
Try this:

string strConnection="user id=logger;password=logger;";
strConnection+="database=MVS;server=4647117000N26";
SqlConnection objSqlConnection = new SqlConnection(strConnection);
objSqlConnection.Open();
DataSet objDataSet = new DataSet();
string strOrderDetails = "SELECT DISTINCT [job_name] FROM [mvs_jobs]";
SqlCommand objOrdDetailCommand = new SqlCommand(strOrderDetails,objSqlConnection);

SqlDataAdapter objODAdapter = new SqlDataAdapter(objOrdDetailCommand);






objODAdapter.Fill(objDataSet);
DropDownList1.DataSource = objDataSet;
DropDownList1.DataTextField = "job_name"
DropDownList1.DataBind();
objSqlConnection.Close();
Thanks, it worked! Now all I have to do is to parse that variable to a new aspx page as parameter and build a crystal report based on the value... piece of cake, eh :)

kind regards
Henrik
Sweden
if you say so.....(piece of cake)......(smile).
Now it is done, I added a reportviewer webcontrol to a new pagepage and used the parameters from the previous page as parameters to the report, then I linked that with a report I have made in Crystal Reports 9. And it WORKS!!!! (on my localhost). I am still having troubles running it in our test-server. I thnk some Crystal dll files haven't been properly registered or even distributed. Crystal Reports works in a funny way, it follows its own standards. And I had to bring out my reference bible on C# in order to understand just how to use that reportviewer control.

Now comes the tricky part, to make the report portal dynamic with logins, profiles, possibility to add new reports to profiles etc etc etc..........the list can be as long as your imagination goes :)

kind regards
Henrik
I might add here as it's the asp.net forum that it is highly advisable to use a datareader to populate in a webform. It's faster than a dataadapter.
I use datareader for any web work. The dataset used with a dataadapter is only of any real use in windows based application.
Hmm, IC. Well I am still learning ASP.NET and I use the same code as I use in my C# desktop programs. Perhaps you can show a small example? I use MS SQL server.

kind regards
Henrik

Wednesday, March 21, 2012

populated a dropdown with data in the rows, but populating a dropdown with names of the co

within my pageload i have
SqlConnection rate;
SqlCommand Selct;
SqlDataReader dbresults;
rate = new SqlConnection( @dotnet.itags.org."xoxo");
rate.Open();
Selct = new SqlCommand( "Select UserID From dbo.Users", rate );
dbresults = Selct.ExecuteReader();
DropDownList1.DataSource = dbresults;
DropDownList1.DataTextField = "UserID*";
DropDownList1.DataBind();
dbresults.Close();
rate.Close();try out

...
myda = New SqlClient.SqlDataAdapter("Select * from <tablename>" , myconnection)
ds = New DataSet()
myda.Fill(ds, "TableName")
Dim dc As DataColumn
For Each dc In ds.Tables(0).Columns
ddl.Items.Add(dc.ColumnName)
Next
.....

HTH
ok heres another one ive been trying to figure out , how do a populate a drop down list with each table name in a database

Populating 2 dim array.

Hello, I have a 7 column data table in ADO.net with 200 rows. I want to learn how to copy the data in my data table to myarray (6,199) as Integar.

Dim myarray (6, 199) As Integar??

For Each myarray In myDataSet.Tables??

??

??

Next??

Hello my friend,

Use the following: -

Dim myarray(6, 199) As Integer

For i As Integer = 0 To dt.Rows.Count - 1

For j As Integer = 0 To dt.Columns.Count - 1
myarray(i, j) = Convert.ToInt32(dt.Rows(i).Item(j))
Next
Next

Kind regards

Scotty

populating & Submitting an external form

Hey All,

In windows forms this can be done using the microsoft web browser control, but how is it done in asp.net either using the axwebbrowser control or httpwebrequest methods

this is an example description only actul sites and stuff will be different

I want my web site to do a search on google so on my site the user enters the input value into a text box, and they press send data.
This is then passed to google via some kind of magic, (ie webrequest) and we populate the google input box and press the search button, when we get our results back from google, i run the response via my regular expression and display the results in my own format.

I dont actully want to spider googles results its just the method is the closest description i can give to what i want to do.

I have been looking at posting data with the httpwebrequest and response methods but im not sure on it.

Can someone advise of the best possible method to handle such events

regards

Carlbump
Try the Google Web Services, even the free subscription allows you loads of searches.
You just make your own pages but use Google to do the searches, very straightforward.
i did say that i only was using google as an example

Populating a check boxlist with info from a database

I have a dropdown box with the value titleid. I also have a checkboxlist with the value of classificationid. How do I populate a checkboxlist when I change the selection in the dropdown?

I have this on pageload

Checkboxlist1.datasource="mystoredprocedure"

checkboxlist1.datatextfield = "description"

checkboxlist1.datavaluefield = "classificationid"

Checkboxlist.databind()

If checkboxlist1.items[i].value = "1' then

checkboxlist1.items[i].selected = true

else

checkboxlist1.items[i].selected = false

Do I need to put something in here to connect/bind to the dropdown box?

You need to handle the "SelectedIndexChanged" event of the dropdown, This event is raised when the selectedItem changes. Please also remember to set the "AutoPostBack" property of the dropdwn to true.

<asp:DropDownListID="DropDownList1"AutoPostBack="true"runat="server"OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"/>

protectedvoid DropDownList1_SelectedIndexChanged(object sender,EventArgs e)

{

//Bind the check box list here again and add any necessary logic you want might want

}s

If this helps please remember to mark post as answer.


Help I'm confused...

I have this as my dropdown:
<asp:DropDownListID="DropDownList1"runat="server"DataSourceID="SqlDataSource1"

DataTextField="Title"DataValueField="TitleID"AutoPostBack="True"OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">

</asp:DropDownList><br/>

<asp:CheckBoxListID="CheckBoxList1"runat="server"DataSourceID="SqlDataSource2"

DataTextField="description"DataValueField="classificationid"RepeatColumns="5"RepeatDirection="Horizontal"BorderStyle="Dashed"CellPadding="2"CellSpacing="2"Height="247px"Width="762px"BorderColor="#CFB37D">

</asp:CheckBoxList><br/>

What do I put on the code behind page for the SelectedIndexChange to bring back the items in the database? If the titleID is selected I want check marks in the checkboxes (classificationid) to show what the user has selected already. Please help!

ProtectedSub CheckBoxList1_SelectedIndexChanged(ByVal senderAsObject,ByVal eAs System.EventArgs)Handles CheckBoxList1.SelectedIndexChanged

EndSub


Okay I've figured some things out... Here's my stored procedure:

CREATE Procedure GetClassID

@.titleid int

AS
SELECT
classifications.[description], titleclassification.classificationid

FROM
classifications inner join titleclassification on titleclassification.classificationid = classifications.classificationid

wheretitleid=@.titleid
GO

I'm trying to code the checkboxlist and having problems

ProtectedSub CheckBoxList1_SelectedIndexChanged(ByVal senderAsObject,ByVal eAs System.EventArgs)Handles CheckBoxList1.SelectedIndexChanged

Dim iAsInteger

Dim chkbxAs CheckBoxList

For i = 0To chkbx.Items.Count - 1

Next

if chkbx.Items[i].SelectedValuethen

CheckBoxList1.Items([i].selected =True)

Else

CheckBoxList1.Items([i].selected =False)

EndIf

CheckBoxList1.DataBind()

EndSub

what am I doing wrong?


Ok, i want to understand one thing. Based on which field do you want the items to be checked? You have 2 fields in your select SP, you need to have a third one and based on it, you set the the items to be checked or not.


I want the classificationid field to be checked. What's the other field to add and how do I set the items to be checked or not? Do I need a Boolean?


if your sql database classificationid field is set to 'bit' you wont need to do anything except checkboxlist1.databind()

it knows 1's are checks and vice versa.

edit: ok so you are using stored procedures. ive never done it that way. what i would do, which is pretty simple imo, is create a fresh checkbox list. let it create a sqldatasource for it. i use the nice little sql generator thing when i create it. select the 2 columns from your database. click the where button and use the control selected index thing. i hope im not being to vague. then lastly you will have to set the dropdownlist to autopostback.




Okay I tried it your way and got the same thing as my stored procedure but how do I get the items to be checked? What do I put for the codebehind

ProtectedSub CheckBoxList1_SelectedIndexChanged(ByVal senderAsObject,ByVal eAs System.EventArgs)Handles CheckBoxList1.SelectedIndexChanged

That's where I'm lost.


its not checkbox1 seletedindexchanged, its dropdownlist1 selectedindex changed. in that code snippet just put checkboxlist1.databind(). when a checkbox list is bound to a bit field, it will check the boxes that are true

please post your most recent aspx page code so i can look at your sqldatasource.


I can't change my classificationid field to a bit field because it will change the entire structure of my database. Ugh. Do I write a function like so to convert to a bit. Is this one okay.

CREATE FUNCTION [Converttobool]
(@.value char(1))
RETURNS bit
BEGIN
declare @.returnvalue bit


if @.value = 'y'
set @.returnvalue = 1
else
set @.returnvalue= 0
return @.returnvalue


END


i think you can just do it in your select statement

cast(columnname, bit)


This is what I have thus far it brings back my items from the database but it's not checked, any ideas?

ProtectedSub DropDownList1_SelectedIndexChanged(ByVal senderAsObject,ByVal eAs System.EventArgs)Handles DropDownList1.SelectedIndexChanged

Dim iAsInteger

For i = 0To CheckBoxList1.Items.Count - 1

If (CheckBoxList1.Items(i).Selected)Then

Response.Write(CheckBoxList1.Items(i).Value)

EndIf

Next

EndSub


you dont need to manually check anything if youve databound it to the sqldatasource... its just checkboxlist1.databind()


Added it cast to my select statement

SELECT
classifications.[description], cast(titleclassification.classificationid as bit)

FROM
classifications inner join titleclassification on titleclassification.classificationid = classifications.classificationid

wheretitleid=@.titleid

Now I'm getting ...Databinding: System.Data.DataRowView does not contain a property with the name classificationid. Any suggestions?


Okay I got rid of the databinding error message, page comes up but still no items are checked? I'm goingIndifferent. I feel that I'm almost there any suggestions?

Here's my select statement:

SELECT
classifications.[description], cast(titleclassification.classificationid as bit)

FROM
classifications inner join titleclassification on titleclassification.classificationid = classifications.classificationid

wheretitleid=@.titleid

What do I put here?

ProtectedSub DropDownList1_SelectedIndexChanged(ByVal senderAsObject,ByVal eAs System.EventArgs)Handles DropDownList1.SelectedIndexChanged

CheckBoxList1.DataBind()

EndSub

Thanks if anyone can assist me!

Populating a checkbox list

Hi - I can get this to work with the first pass, but when it reads the second, it errors with a System.NullReferenceException at the mylistitem.selected=true line.

My CheckBoxList is named cbAvail - and I have a comma delimmited list in a sesion variable "activitywhentext" which holds the text of the checkbox. I am trying to iterate through the comma list, find the checkbox item which relates to it, and select it.

Thanks for any help.

Mark


..
.
Dim i as integer
For i = 0 to mtArrNumItems(Session("activitywhennum"))
Dim mylistitem as new listitem
mylistitem = cbAvail.Items.FindByValue(mtArrRetItem(Session("activitywhennum"),i))
mylistitem.selected = true
Next
..
.
.
Function mtArrNumItems(ByVal mtArr as String) as Integer
Dim arr as Array
arr=Split(mtArr,",")
Return Ubound(arr)
End Function

Function mtArrRetItem(ByVal mtArr As String, ByVal index as integer) as String
Dim arr as Array
arr=Split(mtArr,",")
Return arr(index)
End Function

Have you debugged this and made certain that

cbAvail.Items.FindByValue(mtArrRetItem(Session("activitywhennum"),i))

actually returns an item? If this returns null then your mylistitem object will be null and you'd get an error. In order to figure out why it doesn't find anything you'd have to tell us where this code executes and what your page load event looks like.

Populating a control with HTML file contents, images included?

publicvoid LoadToLabel()
{
using (StreamReader rdr =newStreamReader(FileUpload1.PostedFile.FileName))
{
string uploadedHTML = rdr.ReadToEnd();
textLabel.Text = uploadedHTML.ToString();
}
}

So far I have that, but the problem is that if the HTML file has an image displayed in it, the image doesn't show up because it's just copying the text. How would I be able to transfer the entire HTML page to a control? Like a panel or something like that, is it possible? And have the images come with it?

You should use LiteralControl for this purpose.


So if I switch it to a literal would it display the images as well?


I just switched it to a literal control and it still ignores the images. What must I do?


Yup. The LiteralControl will display the HTML exactly as you create it. See it as a place holder for output you create from code behind. Good luck!


OK, let me get this straight. You upload a HTML document containing <img> tags, which you then want to print out in the page, right?

If you do a view source in the resulting page, how does it look?

If the image urls in the uploaded page are relative then that is maybe what's causing the problem. Please give an example of how this tag looks like.

Also, if you upload a complete HTML document (with head/body) then you will render a page that is not valid (containing duplicate elements).


What does image urls being relative mean? Like pointing to a specific spot and not "~/Images/image.gif" etc.?

I did a view source on the page that uploads and displays the HTML document and yes you're right, there are now duplicate elements. It uploads everything within the uploaded documents <HTML></HTML> tags. How do I go about just grabbing what's in the body, and not the body tags themselves as that would be a duplicate element as well?


A relative path is one that does not begin with a / or http://something, example:

<img src="http://pics.10026.com/?src=images/ticker.gif">

A relative path is always calculated from the place where it is accessed.

If your (uploaded) page contains relative image paths, then to display these images correctly, you need to either rebuild the path (by parsing), or copy the contents of the path into the same folder as your upload page (not a viable solution).

Or you could make sure the user uploads all the images as well.

In either way, you have some parsing to do in order to get the uploaded file to display correctly. Also you must parse the file to get the actual contents of the file, and get past <html><body> and so on.

One option you have is to show the uploaded file in an iframe which would allow you to show the document as-is (although images would still require parsing).


How would I go about parsing the uploaded file so it displays properly with the images included within the literal control?


Strange... I could almost see that question comingWink Well, parsing text is not trivial, and I am not able to give you the code as it would take some time to develop and test. But here's how I would do: Define a regexp, that finds <img tags, and then replaces the src value with your "path prefixed" value.

Problem is that these tags can come in so many flavours, it's almost impossible to guarantee that the parser matches them correctly. Parsing HTML is kind of re-inventing the wheel again (the wheel being the browser ;-)

Uhm, I'm sorry, can't help you any further with this. But if you google a little on Regular expressions and spend some time trialing and erroring then you might reach your goal. Good luck!


Thank you so much for your help!

Populating a data grid with a stored procudure w/parameters

All,

I'm trying to populate a datagrid with a data adapter that uses a stored
procedure with a parameter. I get the below error when I run my code
(as seen below). Any hints?

If I delete the .value = "Business Acumen" at the end of the add
parameters statement & put the below code on a different row, the error
goes away, but I get back an empty dataset.

Me.cmdUYP.Parameters("@dotnet.itags.org.web_competency_name").Value = "Business Acumen"

Error Msg:
The SqlParameterCollection only accepts non-null SqlParameter type
objects, not Boolean objects.

My Code:

Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Text.RegularExpressions
Imports System.Text

Public Class UYP_Class
Inherits System.Web.UI.Page
Protected WithEvents btnFLMClose As System.Web.UI.WebControls.Button
Dim previousCat As String
Dim previousComp As String
Protected WithEvents linkIntelU As
System.Web.UI.WebControls.HyperLink
Protected WithEvents Image1 As System.Web.UI.WebControls.Image
Protected WithEvents btnClose As System.Web.UI.WebControls.Button
Protected WithEvents lnkIntelLibrary As
System.Web.UI.WebControls.HyperLink
Protected WithEvents lnkBuyOnline As
System.Web.UI.WebControls.HyperLink
Protected WithEvents conUYP As System.Data.SqlClient.SqlConnection
Protected WithEvents lblError As System.Web.UI.WebControls.Label
Protected WithEvents daUYP As System.Data.SqlClient.SqlDataAdapter
Protected WithEvents cmdUYP As System.Data.SqlClient.SqlCommand
Protected WithEvents DsUYP1 As FDO.dsUYP
Protected WithEvents lnkAllCurric As
System.Web.UI.WebControls.HyperLink
Protected WithEvents lnkHelp As System.Web.UI.WebControls.HyperLink
Protected WithEvents dgUYP As System.Web.UI.WebControls.DataGrid
Protected WithEvents btnExportExcel As
System.Web.UI.WebControls.Button

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.conUYP = New System.Data.SqlClient.SqlConnection()
Me.daUYP = New System.Data.SqlClient.SqlDataAdapter()
Me.cmdUYP = New System.Data.SqlClient.SqlCommand()
Me.DsUYP1 = New FDO.dsUYP()
CType(Me.DsUYP1,
System.ComponentModel.ISupportInitialize).BeginIni t()
'
'conUYP
'
Me.conUYP.ConnectionString = "data source=OREA2SQL017;initial
catalog=Fin_Trng_DB;password=abcd$1234;persist se" & _
"curity info=True;user id=FinTrngUserGrp"
'
'daUYP
'
Me.daUYP.SelectCommand = Me.cmdUYP
'
'cmdUYP
'
Me.cmdUYP.CommandText = "dbo.[prc_uyp_curriculum]"
Me.cmdUYP.CommandType = System.Data.CommandType.StoredProcedure
Me.cmdUYP.Connection = Me.conUYP
Me.cmdUYP.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@dotnet.itags.org.web_competency_name",
System.Data.SqlDbType.NVarChar, 50).Value = "Business Acumen")

'
'DsUYP1
'
Me.DsUYP1.DataSetName = "dsUYP"
Me.DsUYP1.Locale = New System.Globalization.CultureInfo("en-US")
Me.DsUYP1.Namespace = "http://www.tempuri.org/dsUYP.xsd"
CType(Me.DsUYP1,
System.ComponentModel.ISupportInitialize).EndInit( )

End Sub

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
'Put user code to initialize the page here
Try
'Me.cmdUYP.Parameters("web_competency_name").Value =
"Business Acumen"
daUYP.Fill(DsUYP1, "prc_uyp_curriculum")
If Not IsPostBack Then
dgUYP.DataSource =
DsUYP1._dbo_prc_uyp_curriculum.DefaultView()
dgUYP.DataBind()
End If
End Sub
End Class

Machelle Chandler
Intel Corporation
Beginning .NET developer
Thanks in advance for the help!

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!Hi Machelle. Try changing this
Me.cmdUYP.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@.web_competency_name",
System.Data.SqlDbType.NVarChar, 50).Value = "Business Acumen")

for
Me.cmdUYP.Parameters.Add("@.web_competency_name",
System.Data.SqlDbType.NVarChar, 50).Value = "Business Acumen";

"Machelle Chandler" <machelle.a.chandler@.intel.com> wrote in message
news:#fF2buClDHA.2232@.TK2MSFTNGP09.phx.gbl...
> All,
> I'm trying to populate a datagrid with a data adapter that uses a stored
> procedure with a parameter. I get the below error when I run my code
> (as seen below). Any hints?
> If I delete the .value = "Business Acumen" at the end of the add
> parameters statement & put the below code on a different row, the error
> goes away, but I get back an empty dataset.
> Me.cmdUYP.Parameters("@.web_competency_name").Value = "Business Acumen"
> Error Msg:
> The SqlParameterCollection only accepts non-null SqlParameter type
> objects, not Boolean objects.
>
> My Code:
> Imports System
> Imports System.Data
> Imports System.Data.SqlClient
> Imports System.Text.RegularExpressions
> Imports System.Text
>
> Public Class UYP_Class
> Inherits System.Web.UI.Page
> Protected WithEvents btnFLMClose As System.Web.UI.WebControls.Button
> Dim previousCat As String
> Dim previousComp As String
> Protected WithEvents linkIntelU As
> System.Web.UI.WebControls.HyperLink
> Protected WithEvents Image1 As System.Web.UI.WebControls.Image
> Protected WithEvents btnClose As System.Web.UI.WebControls.Button
> Protected WithEvents lnkIntelLibrary As
> System.Web.UI.WebControls.HyperLink
> Protected WithEvents lnkBuyOnline As
> System.Web.UI.WebControls.HyperLink
> Protected WithEvents conUYP As System.Data.SqlClient.SqlConnection
> Protected WithEvents lblError As System.Web.UI.WebControls.Label
> Protected WithEvents daUYP As System.Data.SqlClient.SqlDataAdapter
> Protected WithEvents cmdUYP As System.Data.SqlClient.SqlCommand
> Protected WithEvents DsUYP1 As FDO.dsUYP
> Protected WithEvents lnkAllCurric As
> System.Web.UI.WebControls.HyperLink
> Protected WithEvents lnkHelp As System.Web.UI.WebControls.HyperLink
> Protected WithEvents dgUYP As System.Web.UI.WebControls.DataGrid
> Protected WithEvents btnExportExcel As
> System.Web.UI.WebControls.Button
> #Region " Web Form Designer Generated Code "
> 'This call is required by the Web Form Designer.
> <System.Diagnostics.DebuggerStepThrough()> Private Sub
> InitializeComponent()
> Me.conUYP = New System.Data.SqlClient.SqlConnection()
> Me.daUYP = New System.Data.SqlClient.SqlDataAdapter()
> Me.cmdUYP = New System.Data.SqlClient.SqlCommand()
> Me.DsUYP1 = New FDO.dsUYP()
> CType(Me.DsUYP1,
> System.ComponentModel.ISupportInitialize).BeginIni t()
> '
> 'conUYP
> '
> Me.conUYP.ConnectionString = "data source=OREA2SQL017;initial
> catalog=Fin_Trng_DB;password=abcd$1234;persist se" & _
> "curity info=True;user id=FinTrngUserGrp"
> '
> 'daUYP
> '
> Me.daUYP.SelectCommand = Me.cmdUYP
> '
> 'cmdUYP
> '
> Me.cmdUYP.CommandText = "dbo.[prc_uyp_curriculum]"
> Me.cmdUYP.CommandType = System.Data.CommandType.StoredProcedure
> Me.cmdUYP.Connection = Me.conUYP
> Me.cmdUYP.Parameters.Add(New
> System.Data.SqlClient.SqlParameter("@.web_competency_name",
> System.Data.SqlDbType.NVarChar, 50).Value = "Business Acumen")
> '
> 'DsUYP1
> '
> Me.DsUYP1.DataSetName = "dsUYP"
> Me.DsUYP1.Locale = New System.Globalization.CultureInfo("en-US")
> Me.DsUYP1.Namespace = "http://www.tempuri.org/dsUYP.xsd"
> CType(Me.DsUYP1,
> System.ComponentModel.ISupportInitialize).EndInit( )
> End Sub
> 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
> 'Put user code to initialize the page here
> Try
> 'Me.cmdUYP.Parameters("web_competency_name").Value =
> "Business Acumen"
> daUYP.Fill(DsUYP1, "prc_uyp_curriculum")
> If Not IsPostBack Then
> dgUYP.DataSource =
> DsUYP1._dbo_prc_uyp_curriculum.DefaultView()
> dgUYP.DataBind()
> End If
> End Sub
> End Class
> Machelle Chandler
> Intel Corporation
> Beginning .NET developer
> Thanks in advance for the help!
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!

Populating a DataGrid

Hi all. I hope this is the right group
I am trying to populate a datagrid on an ASP.NET page from a MySQL table
using the .NET connector (ByteFX). But for the life of me, I just cannot
work it out. Can someone tell me what I am doing wrong? What I want is to
click a button and the contents of the table from the DB appears in the
DataGrid on my ASP page.
I tried to follow an example on the web and I just got lost. I have posted
my code below.
Dim ConnStr As String
ConnStr = "server=localhost; user
id=test;password=password;database=docum
ents;pooling=false"
Try
Dim TextConn As New MySqlConnection(ConnStr)
Dim TableAdaptor As New MySqlDataAdapter
'Dim CommBuild As New MySqlCommandBuilder
Dim TextDataTable As New DataTable
TextConn.Open()
TableAdaptor = New MySqlDataAdapter("SELECT * FROM daniel",
TextConn)
'CommBuild = New MySqlCommandBuilder(TableAdaptor)
TableAdaptor.Fill(TextDataTable)
TextGrid.DataSource = TextDataTable
IDBox.Text = TextGrid.Items.Count
'TitleBox.Text = TextDataTable.Columns.Count
BodyBox.Text = "Success"
Catch ex As Exception
BodyBox.Text = ex.Message
End Try
Thanks.
Bob
---
I'll have a B please Bob.What is the error you are getting?
"Bob Hollness" <bob@.blockbuster.com> wrote in message
news:ewNHEyM%23EHA.220@.TK2MSFTNGP09.phx.gbl...
> Hi all. I hope this is the right group
> I am trying to populate a datagrid on an ASP.NET page from a MySQL table
> using the .NET connector (ByteFX). But for the life of me, I just cannot
> work it out. Can someone tell me what I am doing wrong? What I want is
> to click a button and the contents of the table from the DB appears in the
> DataGrid on my ASP page.
> I tried to follow an example on the web and I just got lost. I have
> posted my code below.
> Dim ConnStr As String
> ConnStr = "server=localhost; user
> id=test;password=password;database=docum
ents;pooling=false"
> Try
> Dim TextConn As New MySqlConnection(ConnStr)
> Dim TableAdaptor As New MySqlDataAdapter
> 'Dim CommBuild As New MySqlCommandBuilder
> Dim TextDataTable As New DataTable
> TextConn.Open()
> TableAdaptor = New MySqlDataAdapter("SELECT * FROM daniel",
> TextConn)
> 'CommBuild = New MySqlCommandBuilder(TableAdaptor)
> TableAdaptor.Fill(TextDataTable)
> TextGrid.DataSource = TextDataTable
> IDBox.Text = TextGrid.Items.Count
> 'TitleBox.Text = TextDataTable.Columns.Count
> BodyBox.Text = "Success"
> Catch ex As Exception
> BodyBox.Text = ex.Message
> End Try
>
> Thanks.
> --
> Bob
> ---
> I'll have a B please Bob.
>
Hi Bob
try this
say that the table on the db is t1
dim con as new sqlconnection(constr)
dim adapter as new sqladapter("select * from t1",con)
dim ds as new dataset()
adapter.fill(ds,"mytable")
yourGrid.datasource(ds)
yourgrid.datamember("mytable")
yourgrid.databind()
this will work
do not open connection with dataadpter
"Bob Hollness" wrote:

> Hi all. I hope this is the right group
> I am trying to populate a datagrid on an ASP.NET page from a MySQL table
> using the .NET connector (ByteFX). But for the life of me, I just cannot
> work it out. Can someone tell me what I am doing wrong? What I want is t
o
> click a button and the contents of the table from the DB appears in the
> DataGrid on my ASP page.
> I tried to follow an example on the web and I just got lost. I have poste
d
> my code below.
> Dim ConnStr As String
> ConnStr = "server=localhost; user
> id=test;password=password;database=docum
ents;pooling=false"
> Try
> Dim TextConn As New MySqlConnection(ConnStr)
> Dim TableAdaptor As New MySqlDataAdapter
> 'Dim CommBuild As New MySqlCommandBuilder
> Dim TextDataTable As New DataTable
> TextConn.Open()
> TableAdaptor = New MySqlDataAdapter("SELECT * FROM daniel",
> TextConn)
> 'CommBuild = New MySqlCommandBuilder(TableAdaptor)
> TableAdaptor.Fill(TextDataTable)
> TextGrid.DataSource = TextDataTable
> IDBox.Text = TextGrid.Items.Count
> 'TitleBox.Text = TextDataTable.Columns.Count
> BodyBox.Text = "Success"
> Catch ex As Exception
> BodyBox.Text = ex.Message
> End Try
>
> Thanks.
> --
> Bob
> ---
> I'll have a B please Bob.
>
>
Don't worry, I solved it.
I changed "TextGrid.DataSource = TextDataTable" to "TextGrid.DataSource =
TextDataTable.DefaultView"
Bob
---
I'll have a B please Bob.
"Bob Hollness" <bob@.blockbuster.com> wrote in message
news:ewNHEyM%23EHA.220@.TK2MSFTNGP09.phx.gbl...
> Hi all. I hope this is the right group
> I am trying to populate a datagrid on an ASP.NET page from a MySQL table
> using the .NET connector (ByteFX). But for the life of me, I just cannot
> work it out. Can someone tell me what I am doing wrong? What I want is
> to click a button and the contents of the table from the DB appears in the
> DataGrid on my ASP page.
> I tried to follow an example on the web and I just got lost. I have
> posted my code below.
> Dim ConnStr As String
> ConnStr = "server=localhost; user
> id=test;password=password;database=docum
ents;pooling=false"
> Try
> Dim TextConn As New MySqlConnection(ConnStr)
> Dim TableAdaptor As New MySqlDataAdapter
> 'Dim CommBuild As New MySqlCommandBuilder
> Dim TextDataTable As New DataTable
> TextConn.Open()
> TableAdaptor = New MySqlDataAdapter("SELECT * FROM daniel",
> TextConn)
> 'CommBuild = New MySqlCommandBuilder(TableAdaptor)
> TableAdaptor.Fill(TextDataTable)
> TextGrid.DataSource = TextDataTable
> IDBox.Text = TextGrid.Items.Count
> 'TitleBox.Text = TextDataTable.Columns.Count
> BodyBox.Text = "Success"
> Catch ex As Exception
> BodyBox.Text = ex.Message
> End Try
>
> Thanks.
> --
> Bob
> ---
> I'll have a B please Bob.
>

Populating a DataGrid

Hi all. I hope this is the right group

I am trying to populate a datagrid on an ASP.NET page from a MySQL table
using the .NET connector (ByteFX). But for the life of me, I just cannot
work it out. Can someone tell me what I am doing wrong? What I want is to
click a button and the contents of the table from the DB appears in the
DataGrid on my ASP page.

I tried to follow an example on the web and I just got lost. I have posted
my code below.

Dim ConnStr As String

ConnStr = "server=localhost; user
id=test;password=password;database=documents;pooli ng=false"

Try

Dim TextConn As New MySqlConnection(ConnStr)
Dim TableAdaptor As New MySqlDataAdapter
'Dim CommBuild As New MySqlCommandBuilder
Dim TextDataTable As New DataTable

TextConn.Open()

TableAdaptor = New MySqlDataAdapter("SELECT * FROM daniel",
TextConn)

'CommBuild = New MySqlCommandBuilder(TableAdaptor)

TableAdaptor.Fill(TextDataTable)

TextGrid.DataSource = TextDataTable

IDBox.Text = TextGrid.Items.Count
'TitleBox.Text = TextDataTable.Columns.Count
BodyBox.Text = "Success"

Catch ex As Exception

BodyBox.Text = ex.Message

End Try

Thanks.

--

Bob

------------
I'll have a B please Bob.What is the error you are getting?

"Bob Hollness" <bob@.blockbuster.com> wrote in message
news:ewNHEyM%23EHA.220@.TK2MSFTNGP09.phx.gbl...
> Hi all. I hope this is the right group
> I am trying to populate a datagrid on an ASP.NET page from a MySQL table
> using the .NET connector (ByteFX). But for the life of me, I just cannot
> work it out. Can someone tell me what I am doing wrong? What I want is
> to click a button and the contents of the table from the DB appears in the
> DataGrid on my ASP page.
> I tried to follow an example on the web and I just got lost. I have
> posted my code below.
> Dim ConnStr As String
> ConnStr = "server=localhost; user
> id=test;password=password;database=documents;pooli ng=false"
> Try
> Dim TextConn As New MySqlConnection(ConnStr)
> Dim TableAdaptor As New MySqlDataAdapter
> 'Dim CommBuild As New MySqlCommandBuilder
> Dim TextDataTable As New DataTable
> TextConn.Open()
> TableAdaptor = New MySqlDataAdapter("SELECT * FROM daniel",
> TextConn)
> 'CommBuild = New MySqlCommandBuilder(TableAdaptor)
> TableAdaptor.Fill(TextDataTable)
> TextGrid.DataSource = TextDataTable
> IDBox.Text = TextGrid.Items.Count
> 'TitleBox.Text = TextDataTable.Columns.Count
> BodyBox.Text = "Success"
> Catch ex As Exception
> BodyBox.Text = ex.Message
> End Try
>
> Thanks.
> --
> Bob
> ------------
> I'll have a B please Bob.
After
TextGrid.DataSource = TextDataTable

One more line code:

TextGrid.DataBind()

Hope it helps.

Elton Wang
elton_wang@.hotmail.com

>--Original Message--
>Hi all. I hope this is the right group
>I am trying to populate a datagrid on an ASP.NET page
from a MySQL table
>using the .NET connector (ByteFX). But for the life of
me, I just cannot
>work it out. Can someone tell me what I am doing wrong?
What I want is to
>click a button and the contents of the table from the DB
appears in the
>DataGrid on my ASP page.
>I tried to follow an example on the web and I just got
lost. I have posted
>my code below.
> Dim ConnStr As String
> ConnStr = "server=localhost; user
>id=test;password=password;database=documents;pooli ng=false
"
> Try
> Dim TextConn As New MySqlConnection(ConnStr)
> Dim TableAdaptor As New MySqlDataAdapter
> 'Dim CommBuild As New MySqlCommandBuilder
> Dim TextDataTable As New DataTable
> TextConn.Open()
> TableAdaptor = New MySqlDataAdapter("SELECT *
FROM daniel",
>TextConn)
> 'CommBuild = New MySqlCommandBuilder
(TableAdaptor)
> TableAdaptor.Fill(TextDataTable)
> TextGrid.DataSource = TextDataTable
> IDBox.Text = TextGrid.Items.Count
> 'TitleBox.Text = TextDataTable.Columns.Count
> BodyBox.Text = "Success"
> Catch ex As Exception
> BodyBox.Text = ex.Message
> End Try
>
>Thanks.
>--
>Bob
>------------
>I'll have a B please Bob.
>
>.
Hi Bob
try this
say that the table on the db is t1
dim con as new sqlconnection(constr)
dim adapter as new sqladapter("select * from t1",con)
dim ds as new dataset()
adapter.fill(ds,"mytable")
yourGrid.datasource(ds)
yourgrid.datamember("mytable")
yourgrid.databind()
this will work
do not open connection with dataadpter

"Bob Hollness" wrote:

> Hi all. I hope this is the right group
> I am trying to populate a datagrid on an ASP.NET page from a MySQL table
> using the .NET connector (ByteFX). But for the life of me, I just cannot
> work it out. Can someone tell me what I am doing wrong? What I want is to
> click a button and the contents of the table from the DB appears in the
> DataGrid on my ASP page.
> I tried to follow an example on the web and I just got lost. I have posted
> my code below.
> Dim ConnStr As String
> ConnStr = "server=localhost; user
> id=test;password=password;database=documents;pooli ng=false"
> Try
> Dim TextConn As New MySqlConnection(ConnStr)
> Dim TableAdaptor As New MySqlDataAdapter
> 'Dim CommBuild As New MySqlCommandBuilder
> Dim TextDataTable As New DataTable
> TextConn.Open()
> TableAdaptor = New MySqlDataAdapter("SELECT * FROM daniel",
> TextConn)
> 'CommBuild = New MySqlCommandBuilder(TableAdaptor)
> TableAdaptor.Fill(TextDataTable)
> TextGrid.DataSource = TextDataTable
> IDBox.Text = TextGrid.Items.Count
> 'TitleBox.Text = TextDataTable.Columns.Count
> BodyBox.Text = "Success"
> Catch ex As Exception
> BodyBox.Text = ex.Message
> End Try
>
> Thanks.
> --
> Bob
> ------------
> I'll have a B please Bob.
>
Don't worry, I solved it.

I changed "TextGrid.DataSource = TextDataTable" to "TextGrid.DataSource =
TextDataTable.DefaultView"

--

Bob

------------
I'll have a B please Bob.

"Bob Hollness" <bob@.blockbuster.com> wrote in message
news:ewNHEyM%23EHA.220@.TK2MSFTNGP09.phx.gbl...
> Hi all. I hope this is the right group
> I am trying to populate a datagrid on an ASP.NET page from a MySQL table
> using the .NET connector (ByteFX). But for the life of me, I just cannot
> work it out. Can someone tell me what I am doing wrong? What I want is
> to click a button and the contents of the table from the DB appears in the
> DataGrid on my ASP page.
> I tried to follow an example on the web and I just got lost. I have
> posted my code below.
> Dim ConnStr As String
> ConnStr = "server=localhost; user
> id=test;password=password;database=documents;pooli ng=false"
> Try
> Dim TextConn As New MySqlConnection(ConnStr)
> Dim TableAdaptor As New MySqlDataAdapter
> 'Dim CommBuild As New MySqlCommandBuilder
> Dim TextDataTable As New DataTable
> TextConn.Open()
> TableAdaptor = New MySqlDataAdapter("SELECT * FROM daniel",
> TextConn)
> 'CommBuild = New MySqlCommandBuilder(TableAdaptor)
> TableAdaptor.Fill(TextDataTable)
> TextGrid.DataSource = TextDataTable
> IDBox.Text = TextGrid.Items.Count
> 'TitleBox.Text = TextDataTable.Columns.Count
> BodyBox.Text = "Success"
> Catch ex As Exception
> BodyBox.Text = ex.Message
> End Try
>
> Thanks.
> --
> Bob
> ------------
> I'll have a B please Bob.

Populating a datagrid bound list view by a query

Hi,
My question today is below is my code which binds a listview to a databound column in my datagrid, but at the moment the list items are hard coded in. What I actually want is for the listitems to be populated from a lookup style query so possible from a data reader bringing back the ID which will be stored in the bound column but so the user just sees the Text associated with the value. Hope that makes sense.

<asp:TemplateColumn HeaderText="Model">
<ItemTemplate>
<asp:Label runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.FK_StockModelID") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="DropModel" Runat="server">
<asp:ListItem Value="1" text="1"></asp:ListItem>
<asp:ListItem Value="2" text="2"></asp:ListItem>
<asp:ListItem Value="3" text="3"></asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator ControlToValidate="DropModel" text="*" Runat="server" />
</EditItemTemplate>
</asp:TemplateColumn>

I think I can pretty much suss this out if I can work out how to access the dropdown list from tthe codebehind. So if anyone knows that as a starting point, please enlighten me.

PS sorry about the smilies in the code the ASP syntax just happent to be the same code.http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/creatingcustomcolumns.asp
Ok I found this code at the above link but Im struggling to use it, can anyone explain it line by line or tell me how to make it reference my template item shown above.
Private Sub dgNewCarriageBuildSheets_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles dgNewCarriageBuildSheets.ItemDataBound
If e.Item.ItemType = ListItemType.EditItem Then
Dim DRV As DataRowView = CType(e.Item.DataItem, DataRowView)
Dim Cu As String = DRV("ShipVia")
Dim DDL As DropDownList = CType(e.Item.Cells(4).Controls(1), DropDownList)()
Dim SQL As String = _
"SELECT ShipperID, CompanyName FROM Shippers ORDER BY ShipperID"
Dim DA As SqlDataAdapter = New SqlDataAdapter(SQL, ConnStr)
Dim DS As New DataSet
Dim item As ListItem
DA.Fill(DS, "Shippers")
DDL.DataSource = DS.Tables("Shippers").DefaultView
DDL.DataTextField = "CompanyName"
DDL.DataValueField = "ShipperID"
DDL.DataBind()
item = DDL.Items.FindByValue(CurrentShip)
If Not item Is Nothing Then item.Selected = True
End If
End Sub
Yes, you'd do it in the ItemDataBound event. After checking for the ItemType, declare a variable of type Combobox. Set it to e.Item.Cells(x).FindControl(your combobox id), and set the value of that combobox to the value you want from the dataset. You can use e.Item.ItemIndex to get the row number in the repeater/grid/dataset.
Private Sub dgNewCarriageBuildSheets_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles dgNewCarriageBuildSheets.ItemDataBound
If e.Item.ItemType = ListItemType.EditItem Then
Dim cboModel As DropDownList
Dim cboModel As DropDownList = e.Item.Cells(FindControl(DropModel))
'Also I have put DopModel as the ID of the Dropdown list in the item template but it doesnt seem to be recognised? Name DropModel is not declared

End If
End Sub
Fixed

Dim cboModel As DropDownList = e.Item.Cells(11).FindControl("DropModel")

Now to try the next bit...
Nearly there, I am now just getting an error at run time on the line underlined saying cannot convert dbnull to string?
Private Sub dgNewCarriageBuildSheets_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles dgNewCarriageBuildSheets.ItemDataBound
If e.Item.ItemType = ListItemType.EditItem Then
Dim lstItem As ListItem
Dim DRV As DataRowView = CType(e.Item.DataItem, DataRowView)
Dim CurrentModel As String = DRV("FK_StockModelID")
Dim cboModel As DropDownList = e.Item.Cells(11).FindControl("DropModel")
Main.objCarriageBuildSheet.GetStockModels() 'Populates a dataset
cboModel.DataSource = Main.objCarriageBuildSheet.dds_StockModels.dt_StockModels
cboModel.DataTextField = "Model"
cboModel.DataValueField = "FK_StockModelID"
cboModel.DataBind()
lstItem = cboModel.Items.FindByValue(CurrentModel)
If Not lstItem Is Nothing Then lstItem.Selected = True
End If
End Sub
DataBinder.Eval(e.Item.DataItem, "FK_StockModelID")
Like this ?
If e.Item.ItemType = ListItemType.EditItem Then

Dim lstItem As ListItem
Dim DRV As DataRowView = CType(e.Item.DataItem, DataRowView)
Dim CurrentModel As String = DataBinder.Eval(e.Item.DataItem, "FK_StockModelID") 'DRV("FK_StockModelID")
Dim cboModel As DropDownList = e.Item.Cells(11).FindControl("DropModel")

Main.objCarriageBuildSheet.GetStockModels() 'Populates a dataset
cboModel.DataSource = Main.objCarriageBuildSheet.dds_StockModels.dt_StockModels
cboModel.DataTextField = "Model"
cboModel.DataValueField = "FK_StockModelID"
cboModel.DataBind()
lstItem = cboModel.Items.FindByValue(CurrentModel)

If Not lstItem Is Nothing Then lstItem.Selected = True

End If

I still get same error
Hmm... maybe before you call that line, you should check whether e.Item.DataItem evaluates to null... place a breakpoint there and have a look at it.
It evaluates to a system.data.datarowview object
Hi Mendhak, I have finally solved the problem a different way.

My HTML code looks like this now, the main difference is I have set the datasource to a function in my code behind page.
<asp:TemplateColumn HeaderText="Model">
<ItemTemplate>
<asp:Label runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.FK_StockModelID") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList id=DropModel Runat="server" DataValueField="ModelID" DataTextField="BrandModel" DataSource="<%# PopulateList %>" >
</asp:DropDownList>
<asp:RequiredFieldValidator id="RequiredFieldValidator1" Runat="server" text="*" ControlToValidate="DropModel"></asp:RequiredFieldValidator>
</EditItemTemplate>
</asp:TemplateColumn>

The function simply returns a previously filled dataset.
Public Function PopulateList() As DataSet

Return Main.objCarriageBuildSheet.dds_StockModels
End Function

this seems to be working nicely.

Populating a datagrid ... how is it done normally?

Hi All ...
I'm writing a small shopping cart app (school assignment) and need to list
all the books that a user selects.
I have created a "BookBasket" object that contains among other things an
arraylist of the user selected books. The "book" object contains isbn,title
price and quantity information.
I'd like to display the contents of the BookBasket in a datagrid control.
I assume that to start with I'd have to iterate through the basket to
identify each books information, but then how do I populate the datagrid
from there?
It seems from what I've read,that it is easier to populate a datagrid from a
datasource, but I don't know how that would relate to what I'm doing.
any clues or links to examples would be much appreciated.
Thanks in advance
Prime.Prime,
There is a plethora of examples on using a datagrid control. Search
google and you will find more than you need. The second article outlines
what kind of datasources a datagrid will accept, an array is a valid data
source so you won't have to write any code to fill another control. The
third snippit supports my last statement.
Hope this helps.
Jared
Here's one to get you started
http://samples.gotdotnet.com/quicks...c_datagrid.aspx
http://msdn.microsoft.com/library/d...nadodataset.asp
You can bind to the following structures if their elements expose public
properties:
a.. Any component that implements the IList interface. This includes
single-dimension arrays
"Prime" <not@.real.address> wrote in message
news:uIhFN$0pEHA.1668@.TK2MSFTNGP14.phx.gbl...
> Hi All ...
> I'm writing a small shopping cart app (school assignment) and need to list
> all the books that a user selects.
> I have created a "BookBasket" object that contains among other things an
> arraylist of the user selected books. The "book" object contains
> isbn,title
> price and quantity information.
> I'd like to display the contents of the BookBasket in a datagrid control.
> I assume that to start with I'd have to iterate through the basket to
> identify each books information, but then how do I populate the datagrid
> from there?
> It seems from what I've read,that it is easier to populate a datagrid from
> a
> datasource, but I don't know how that would relate to what I'm doing.
> any clues or links to examples would be much appreciated.
> Thanks in advance
> Prime.
>
>
Hi Jared,
I think you've helped me before ... thank-you again.
I found the gotdotnet sample very helpful. We are currently using a text
book that is poor by any standard so your assistance is very much
appreciated.
The second sample was good, but we're not allowed to use a database
interface! I originally coded my app that way,but was told that it was
unacceptable. :( I found the database version extremely simple to code.)
Again, thanks for you assistance.
Prime.
"Jared" <ask_me_for_it@.nospam.com> wrote in message
news:10lpaldc1uahra6@.corp.supernews.com...
> Prime,
> There is a plethora of examples on using a datagrid control. Search
> google and you will find more than you need. The second article outlines
> what kind of datasources a datagrid will accept, an array is a valid data
> source so you won't have to write any code to fill another control. The
> third snippit supports my last statement.
> Hope this helps.
> Jared
> Here's one to get you started
>
http://samples.gotdotnet.com/quicks... />
agrid.aspx
>
http://msdn.microsoft.com/library/d...nadodataset.asp
> You can bind to the following structures if their elements expose public
> properties:
> a.. Any component that implements the IList interface. This includes
> single-dimension arrays
> "Prime" <not@.real.address> wrote in message
> news:uIhFN$0pEHA.1668@.TK2MSFTNGP14.phx.gbl...
list
control.
from
>

Populating a datagrid ... how is it done normally?

Hi All ...

I'm writing a small shopping cart app (school assignment) and need to list
all the books that a user selects.

I have created a "BookBasket" object that contains among other things an
arraylist of the user selected books. The "book" object contains isbn,title
price and quantity information.

I'd like to display the contents of the BookBasket in a datagrid control.

I assume that to start with I'd have to iterate through the basket to
identify each books information, but then how do I populate the datagrid
from there?

It seems from what I've read,that it is easier to populate a datagrid from a
datasource, but I don't know how that would relate to what I'm doing.

any clues or links to examples would be much appreciated.

Thanks in advance

Prime.Prime,
There is a plethora of examples on using a datagrid control. Search
google and you will find more than you need. The second article outlines
what kind of datasources a datagrid will accept, an array is a valid data
source so you won't have to write any code to fill another control. The
third snippit supports my last statement.
Hope this helps.
Jared

Here's one to get you started
http://samples.gotdotnet.com/quicks...c_datagrid.aspx

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

You can bind to the following structures if their elements expose public
properties:

a.. Any component that implements the IList interface. This includes
single-dimension arrays

"Prime" <not@.real.address> wrote in message
news:uIhFN$0pEHA.1668@.TK2MSFTNGP14.phx.gbl...
> Hi All ...
> I'm writing a small shopping cart app (school assignment) and need to list
> all the books that a user selects.
> I have created a "BookBasket" object that contains among other things an
> arraylist of the user selected books. The "book" object contains
> isbn,title
> price and quantity information.
> I'd like to display the contents of the BookBasket in a datagrid control.
> I assume that to start with I'd have to iterate through the basket to
> identify each books information, but then how do I populate the datagrid
> from there?
> It seems from what I've read,that it is easier to populate a datagrid from
> a
> datasource, but I don't know how that would relate to what I'm doing.
> any clues or links to examples would be much appreciated.
> Thanks in advance
> Prime.
>
Hi Jared,

I think you've helped me before ... thank-you again.

I found the gotdotnet sample very helpful. We are currently using a text
book that is poor by any standard so your assistance is very much
appreciated.

The second sample was good, but we're not allowed to use a database
interface! I originally coded my app that way,but was told that it was
unacceptable. :( I found the database version extremely simple to code.)

Again, thanks for you assistance.

Prime.

"Jared" <ask_me_for_it@.nospam.com> wrote in message
news:10lpaldc1uahra6@.corp.supernews.com...
> Prime,
> There is a plethora of examples on using a datagrid control. Search
> google and you will find more than you need. The second article outlines
> what kind of datasources a datagrid will accept, an array is a valid data
> source so you won't have to write any code to fill another control. The
> third snippit supports my last statement.
> Hope this helps.
> Jared
> Here's one to get you started
http://samples.gotdotnet.com/quicks...c_datagrid.aspx
>
http://msdn.microsoft.com/library/d...nadodataset.asp
> You can bind to the following structures if their elements expose public
> properties:
> a.. Any component that implements the IList interface. This includes
> single-dimension arrays
> "Prime" <not@.real.address> wrote in message
> news:uIhFN$0pEHA.1668@.TK2MSFTNGP14.phx.gbl...
> > Hi All ...
> > I'm writing a small shopping cart app (school assignment) and need to
list
> > all the books that a user selects.
> > I have created a "BookBasket" object that contains among other things an
> > arraylist of the user selected books. The "book" object contains
> > isbn,title
> > price and quantity information.
> > I'd like to display the contents of the BookBasket in a datagrid
control.
> > I assume that to start with I'd have to iterate through the basket to
> > identify each books information, but then how do I populate the datagrid
> > from there?
> > It seems from what I've read,that it is easier to populate a datagrid
from
> > a
> > datasource, but I don't know how that would relate to what I'm doing.
> > any clues or links to examples would be much appreciated.
> > Thanks in advance
> > Prime.

populating a datagrid from a parameterized procedure during page load

I have a datagrid control on my page populated from a parameterized stored procedure. The parameter comes from a label control on my page as seen below. I cannot get the grid to populate. Any suggestions?

Dim LocalIP = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
If LocalIP =""Then
LocalIP = Request.ServerVariables("REMOTE_ADDR")
EndIf
Label1.Text = LocalIP

TIA <JP>

Hi paskettj,

first check if Label1.text has been assigned to the correct value(mean, what's the value of " LocalIP" ? you can use debug, or response.write to monitor it);

secondly,check if your sotred procedure has returned the correct data;

and the third, pls check if you have use datagrid correctly. To get your datagrid control populated with corresponding data,First, you need to set the correct DataSource or DataSourceID, then call the Databind() method. It doesn't matter where you get your data from(whether it's from a table,backend database, from parameterized stored procedure...etc).

for more detailed information, i suggest you reading some material by clicking the following links:

http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.basedatalist.datasource(VS.71).aspx (the sample within this page should help u use datagrid)

http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.datagrid.aspx (to a overview of datagird class)

hope my suggestion helps :)

Populating a datagrid from two separate data sources

Hi all,

I have an interesting situation. I have a datagrid I'm currently populating
using a dataset but now I need to introduce some extra records into this.
I'm unsure of which method to use. Is it possible for me to populate (fill)
a dataset from another dataset and at the same time, make sure there are no
duplicates?

Regards
John.John,

Check out the Merge method of the DataSet class. It might just be what
you're after.

--
Carsten Thomsen
Enterprise Development with Visual Studio .NET, UML, and MSF
http://www.apress.com/book/bookDisplay.html?bID=105
"John" <a@.b.com> wrote in message
news:uITE8tpVDHA.384@.TK2MSFTNGP12.phx.gbl...
> Hi all,
> I have an interesting situation. I have a datagrid I'm currently
populating
> using a dataset but now I need to introduce some extra records into this.
> I'm unsure of which method to use. Is it possible for me to populate
(fill)
> a dataset from another dataset and at the same time, make sure there are
no
> duplicates?
> Regards
> John.