Showing posts with label insert. Show all posts
Showing posts with label insert. Show all posts

Monday, March 26, 2012

Populate Database from Arraylist

I would like to know how to Populate the SQL Database column using the Arraylist

I'm sure its gonna be INSERT...one example i need

INSERT INTO tempPrice(price) VALUES ( "...............")

How should i declare Arraylist in it? I have a list of values inside the arraylist and i just want the entire column to be filled with it.

Thanks.

HTM

Unfortunately there is no direct way to do this. You have to execute each sql query for each row.

Regards

Saturday, March 24, 2012

Populate foreign key in InsertTemplate of FormView

Hello all,

How would I populate a foreign key value in a label field of a FormView when
FormView changes mode to Insert? So that I can insert foreign key.

Explanation:
Suppose there are two tables in database, EMPLOYEE (list of employees) and
EMPLOYEE_DOCS (list of documents of every employee). table EMPLOYEE_DOCS
have a foreign key field EMPLOYEE_ID. When I use FormView's Insert mode for
EMPLOYEE_DOCS, I want to to explicitly take foreign key, so that it wont go
blank when inserting in database or user wont need to type it. I have
everything in Panels (webcontrol)

Thank you for help.
MirajThanks all, I figured out

I did this:

Protected Sub FormView1_ItemInserting(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.FormViewInsertEventArgs) Handles
FormView1.ItemInserting

e.Values("EMPLOYEE_ID") =
GridView1.Rows(GridView1.SelectedIndex).Cells(1).T ext ' cells(1).text is the
foreign key

End Sub

"Miraj Haq" <mirajhaq-n-o-s-p-a-m@.yahoo.com> wrote in message
news:epbuhXYhFHA.1444@.TK2MSFTNGP10.phx.gbl...
> Hello all,
> How would I populate a foreign key value in a label field of a FormView
> when FormView changes mode to Insert? So that I can insert foreign key.
> Explanation:
> Suppose there are two tables in database, EMPLOYEE (list of employees) and
> EMPLOYEE_DOCS (list of documents of every employee). table EMPLOYEE_DOCS
> have a foreign key field EMPLOYEE_ID. When I use FormView's Insert mode
> for EMPLOYEE_DOCS, I want to to explicitly take foreign key, so that it
> wont go blank when inserting in database or user wont need to type it. I
> have everything in Panels (webcontrol)
> Thank you for help.
> Miraj

Populate insert form field from GridView selection

Hi,

I'm trying to do something that seems like it should be simple, but I'm having trouble getting it to work. I have a page with a GridView and a FormView in Insert mode.

When the user selects a row in the gridview, I want to take the data keys from that selection and populate them to the appropriate textboxes in the form. I'm trying to do this in the

"GridView1_SelectedIndexChanged event" with the following code:

TextBox t;

t = (TextBox)FormView1.FindControl("myTextBox");

t.Text = (String)GridView1.SelectedDataKey.Values[0];

The text in "myTextBox" doesn't change, it remains blank. I've tried to find another event in which to put this code but so far no luck. I'm a newbie so I'm sure it's something obvious.

Can anyone help me with this? Thanks in advance.

Try moving your code to the FormView.DataBound event.


Hi Ed,

When I do that, I get "Object reference not set to an instance of an object. " I'm guessing that this is because the formview1_databound fires when the page is first loading, before there is a selected key from the gridview. I'm not sure that this is the case, it's just my best guess.

Do you have any suggestion for a workaround or alternate approach?

Thanks.


Once try this

ProtectedSub GridView1_SelectedIndexChanged(ByVal senderAsObject,ByVal eAs System.EventArgs)Handles GridView1.SelectedIndexChanged

Formview1.PageIndex = GridView1.SelectedIndex

EndSub


Hi Mahesh,

Okay, now I have this code but I still don't see the text I want populated into the text box. What am I doing wrong?

protectedvoid GridView1_SelectedIndexChanged(object sender,EventArgs e)

{

FormView1.PageIndex = GridView1.SelectedIndex;

TextBox t;

t = (TextBox)FormView1.FindControl("myTextBox");

t.Text = (String)GridView1.SelectedDataKey.Values[0];

}


How about this:


protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{

for (int i = 0; i < GridView1.Rows.Count; i++)
{
if (GridView1.SelectedIndex == i)
{
TextBox t;

t = (TextBox)FormView1.FindControl("myTextBox");
t.Text = (String)GridView1.SelectedDataKey.Values[0];
}
}
}


Within your FormView.DataBound event, simply place a conditional statement which checks for the existence of a SelectedItem.

if (!GridView1.SelectedIndex.Equals(-1))


That did it! Thanks very much (I told you that I was a newbie :-).

Wednesday, March 21, 2012

Populating a DropDownList

Is there a way to manually insert rows into a dropdownlist.
I nneed to insert a value and a display text.Yes, you may use " DropDownList.Items.Add" or "Items.Insert".
How do you add a value and a display text?
ddlb.Add("50","New York") does not work. It appears to only take one argument.
OK. Do it like this:

Dim newItem As ListItem = New ListItem("New York", "50")
ddlb.Items.Add(newItem)

This will add a new item at bottom of your DDL, if you want add it in a certain palce, you amy do like this:

ddlb.Items.Insert(0,newItem)

This will add it in the very top.