How to initialize textbox value in FormView in InsertItemMode?

G

Guest

Hi,

I want to insert some value into textbox automaticly in FormView
InsertItemMode. This value may be a session value or to click a button to
insert it. I try to replace <%# bind("blah")%> description by
(String)Session.contains["blah"]. This method is work when showing on the
screen. But it will not store into the database source because I replace the
<%#bind %>. Is there any good way to achieve my thinking?
 
G

Guest

Bind the textbox to the data source where you want the data to go then put
the value in the text box by putting something based on the following code in
the ModeChanging event.

if (e.NewMode = DetailsViewMode.Insert)
{
Code to asign value to textbox...
}
 
G

Guest

Yuchang,

You can leave the binding <%# bind("blah")%> for what it is to preserve the
databinding functionality.
Use the FindControl method to automatically fill your control:

protected void FormView1_PreRender(object sender, EventArgs e)
{
string strDefaultProdName = "Product name";
if (FormView1.CurrentMode == FormViewMode.Insert &&
((TextBox)FormView1.FindControl("ProductNameTextBox")).Text.Length==0)
((TextBox)FormView1.FindControl("ProductNameTextBox")).Text =
strDefaultProdName;
}

Regards, Dustin.
 
G

Guest

That is what I really need!!
Thank you very much~~

Dustin van de Sande said:
Yuchang,

You can leave the binding <%# bind("blah")%> for what it is to preserve the
databinding functionality.
Use the FindControl method to automatically fill your control:

protected void FormView1_PreRender(object sender, EventArgs e)
{
string strDefaultProdName = "Product name";
if (FormView1.CurrentMode == FormViewMode.Insert &&
((TextBox)FormView1.FindControl("ProductNameTextBox")).Text.Length==0)
((TextBox)FormView1.FindControl("ProductNameTextBox")).Text =
strDefaultProdName;
}

Regards, Dustin.

yuchang said:
Hi,

I want to insert some value into textbox automaticly in FormView
InsertItemMode. This value may be a session value or to click a button to
insert it. I try to replace <%# bind("blah")%> description by
(String)Session.contains["blah"]. This method is work when showing on the
screen. But it will not store into the database source because I replace the
<%#bind %>. Is there any good way to achieve my thinking?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top