Showing posts with label value. Show all posts
Showing posts with label value. Show all posts

Wednesday, March 28, 2012

The clicking twice hair pulling doesnt do anything problem!

I have a single page in which everything is loaded from user controls based upon a specific value in the URL. The user controls are dynamically loaded (only load the user controls I need based upon the key in the URL). Within the user control is a form with a single button. When I click the button, nothing happens. When I click it again it does a full postback but all user controls are gone and I haven't the slightest idea if it upated or not. Now the form is in an update panel so it shouldn't be doing a post back.

To reiterate:

1. single page (call it default.aspx)
2. click a link with the key in the url (kind of like "?k=1048")
3. default.aspx runs through a case statement and find the key value that matches the URL then loads the user control.
4. user control has form on it
5. click the submit button, nothing happens. Click it again and it does a postback and all user controls are gone (AJAX didn't work).

So, any ideas about having to click twice and also why the update panel doesn't seem to be working?

thanks

^_^

ps. if i put the user control in a completely separate page where it isn't dynamically loaded, things work as intended.

To start with, when using Dynamic Controls, you should already know that you should RECREATE your controls on every page request. Keeping this in mind, you should keep track of which UserControl was loaded before and then reload it again!

Hope this helps,
Regards


That's nice but didn't help at all nor directed me to even an idea

What I did find was that when I removed the triggers from the update panel then the double-clicking went away and it operated as intended. but I wonder what will happen when I have multiple controls on a page that each have an update panel and I update one, will it cause the others to fire as well even with the mode set to conditional.

Does anyone have an idea of this cause that knows what they are talking about.

thanks

Monday, March 26, 2012

The conversion of a char data type to a datetime data type resulted....

Hi,

I'm trying to insert a date time value into a SQL Server Database field of type date time using a c# web form.
I get the following error...
"The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value. The statement has been terminated"

My SQL looks like this:


INSERT INTO tblname (fldname) VALUES ('" + DateTime.Now.ToString() + "')"

What am I doing wrong?Remove the ToString() method as that is changing the DateTime type to a string (or Char type) ...at least thats what it looks like.
Nope sorry to say that didn't work.

My C# now looks like


SqlConnection myConn = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["eTeam_ConnectionString"].ToString());
string mySQL = "INSERT INTO tblname (datestamp) VALUES ('" + DateTime.Now + "')";
SqlCommand myCMD = new SqlCommand(mySQL, myConn);
myConn.Open();
myCMD.ExecuteNonQuery();
myConn.Close();
myCMD.Dispose();
myConn.Dispose();

And the field 'datestamp' is a SQL Server Data Type datetime

Anyone else?
You can use getDate() method of SQL server to update date.

INSERT INTO tblname (datestamp) VALUES (getDate())";
Thanks for that - definately half way to solving my problem.
What if I need to take a value from an ASP:Calendar control?
Is there a ToDate() function that will convert it as required?
You can use

Calendar1.SelectedDate.ToShortDateString())

which will convert this date into short date format.

Thursday, March 22, 2012

The first value of a dropdownlist

How can I show a value at the beginning of the dropdownlist with my
structure? This initial value isn' t in the database, for instance
'(Select)'.

<script language="VB" runat="server"
Sub Page_Load()

Dim strConnection As New
SqlConnection("Server=nou;database=market1;uid=sa;password=;")

Dim families As string = "SELECT family_Name FROM
Families;"

Dim DS1 As DataSet
Dim CommandFamilies As SqlDataAdapter

CommandFamilies = New SqlDataAdapter(families, strConnection)

DS1 = new DataSet()
CommandFamilies.Fill(DS1, "Families")

MySelect1.DataSource=
DS1.Tables("Families").DefaultView
MySelect1.DataBind()

End Sub

</script
...

<form runat="server"
<asp:dropdownlist id="MySelect1"
DataTextField="family_Name" runat="server"
class="letter1"
</asp:dropdownlist
...

--== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==--
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
--= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =--not sure of the VB .net syntax, but here it is in C#

ListItem li = new ListItem();
YourDDL.Items.Add(li, 0);

put's a blank item at the beginning of your drop down list

"cesark" <cesar_casafont@.hotmail-dot-com.no-spam.invalid> wrote in message
news:400db905$1_2@.127.0.0.1...
> How can I show a value at the beginning of the dropdownlist with my
> structure? This initial value isn' t in the database, for instance
> '(Select)'.
>
> <script language="VB" runat="server">
> Sub Page_Load()
> Dim strConnection As New
> SqlConnection("Server=nou;database=market1;uid=sa;password=;")
> Dim families As string = "SELECT family_Name FROM
> Families;"
>
> Dim DS1 As DataSet
> Dim CommandFamilies As SqlDataAdapter
> CommandFamilies = New SqlDataAdapter(families, strConnection)
> DS1 = new DataSet()
> CommandFamilies.Fill(DS1, "Families")
>
> MySelect1.DataSource=
> DS1.Tables("Families").DefaultView
> MySelect1.DataBind()
>
> End Sub
> </script>
>
> ...
> <form runat="server">
> <asp:dropdownlist id="MySelect1"
> DataTextField="family_Name" runat="server"
> class="letter1">
> </asp:dropdownlist>
> ...
>
>
> --== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet
News==--
> http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000
Newsgroups
> --= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption
=--
I have already achieved it 8) . The right code was:

MySelect2.Items.Insert(0, "(Select a value)")
MySelect2.SelectedIndex = 0

Just before of 'MySelect2.DataBind()'

Thank you anyway :)

--== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==--
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
--= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =--

Tuesday, March 13, 2012

The ItemArray

hey all,
I'm trying to get to an Item of a DataRow.ItemArray.
I can specify the index value and retrieve the item i need but it says you
can get to the item using the ColumnName (string) as well. When I try to
specify the column string it doesn't retrieve it.
Could it be because my GridView is bound to a stored procedure? The store
procedure is returning a table.
thanks,
rodcharThe ItemArray property of a DataRow is of type object array, doesn't expose
a
Column name. You might be thinking of something else.
Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net
"rodchar" wrote:

> hey all,
> I'm trying to get to an Item of a DataRow.ItemArray.
> I can specify the index value and retrieve the item i need but it says you
> can get to the item using the ColumnName (string) as well. When I try to
> specify the column string it doesn't retrieve it.
> Could it be because my GridView is bound to a stored procedure? The store
> procedure is returning a table.
> thanks,
> rodchar
>
I'm sorry I meant the DataRow object.
"Peter Bromberg [C# MVP]" wrote:
> The ItemArray property of a DataRow is of type object array, doesn't expos
e a
> Column name. You might be thinking of something else.
> Peter
> --
> Site: http://www.eggheadcafe.com
> UnBlog: http://petesbloggerama.blogspot.com
> Short urls & more: http://ittyurl.net
>
>
> "rodchar" wrote:
>
rodchar wrote:
> hey all,
> I'm trying to get to an Item of a DataRow.ItemArray.
> I can specify the index value and retrieve the item i need but it says you
> can get to the item using the ColumnName (string) as well. When I try to
> specify the column string it doesn't retrieve it.
> Could it be because my GridView is bound to a stored procedure? The store
> procedure is returning a table.
> thanks,
> rodchar
>
foreach (DataRow r in dtCompare.Rows)
{
string searchNutrNo = r["nutr_no"].ToString();

The ItemArray

hey all,
I'm trying to get to an Item of a DataRow.ItemArray.
I can specify the index value and retrieve the item i need but it says you
can get to the item using the ColumnName (string) as well. When I try to
specify the column string it doesn't retrieve it.

Could it be because my GridView is bound to a stored procedure? The store
procedure is returning a table.

thanks,
rodcharThe ItemArray property of a DataRow is of type object array, doesn't expose a
Column name. You might be thinking of something else.
Peter

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net
"rodchar" wrote:

Quote:

Originally Posted by

hey all,
I'm trying to get to an Item of a DataRow.ItemArray.
I can specify the index value and retrieve the item i need but it says you
can get to the item using the ColumnName (string) as well. When I try to
specify the column string it doesn't retrieve it.
>
Could it be because my GridView is bound to a stored procedure? The store
procedure is returning a table.
>
thanks,
rodchar
>
>


I'm sorry I meant the DataRow object.

"Peter Bromberg [C# MVP]" wrote:

Quote:

Originally Posted by

The ItemArray property of a DataRow is of type object array, doesn't expose a
Column name. You might be thinking of something else.
Peter
>
--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net
>
>
>
>
"rodchar" wrote:
>

Quote:

Originally Posted by

hey all,
I'm trying to get to an Item of a DataRow.ItemArray.
I can specify the index value and retrieve the item i need but it says you
can get to the item using the ColumnName (string) as well. When I try to
specify the column string it doesn't retrieve it.

Could it be because my GridView is bound to a stored procedure? The store
procedure is returning a table.

thanks,
rodchar


rodchar wrote:

Quote:

Originally Posted by

hey all,
I'm trying to get to an Item of a DataRow.ItemArray.
I can specify the index value and retrieve the item i need but it says you
can get to the item using the ColumnName (string) as well. When I try to
specify the column string it doesn't retrieve it.
>
Could it be because my GridView is bound to a stored procedure? The store
procedure is returning a table.
>
thanks,
rodchar
>
>


foreach (DataRow r in dtCompare.Rows)
{
string searchNutrNo = r["nutr_no"].ToString();

the meaning of life and gridviews e.newValue

hey all,
what is the purpose of e.NewValues inside the GridView1_RowUpdating routine?
i've seen examples where you findControl then assign that value to
e.NewValues, but that seems like an extra step.

thanks,
rodchar"rodchar" <rodchar@.discussions.microsoft.comwrote in message
news:355B7331-25E9-4E98-BDC7-A7D8D9BC0C52@.microsoft.com...

Quote:

Originally Posted by

hey all,
what is the purpose of e.NewValues inside the GridView1_RowUpdating


routine?

Quote:

Originally Posted by

i've seen examples where you findControl then assign that value to
e.NewValues, but that seems like an extra step.
>
thanks,
rodchar


I use is to validate serverside. Here is an example

Sub EmailGrid_Updating(sender as object, e as GridViewUpdateEventargs)
'Check format of new data
dim bCancel as boolean = false
msg1.text = string.empty
dim strEmailAddress as string = string.empty
if not e.newvalues(0) is nothing then
strEmailAddress = Server.htmlencode(e.newvalues(0).tostring())
end if
BCancel= Regex.IsMatch(strEmailAddress,
"^([\w-\.]+)@.((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-
Z]{2,4}|[0-9]{1,3})(\]?)$")
if BCancel then
dim strDate as string = string.empty
if not e.newvalues(2) is nothing then
strDate = Server.htmlencode(e.newvalues(2).tostring())
BCancel = IsDate(strDate)
if BCancel then
if (year(ctype(strDate,datetime)) < 2000) then
BCancel = false

end if
if not bCancel then msg1.text = "Invalid Date"
end if
else
msg1.text = "Invalid Email Address"
end if
e.Cancel = not bCancel
End sub
thank you i'll take a look.

"vMike" wrote:

Quote:

Originally Posted by

>
"rodchar" <rodchar@.discussions.microsoft.comwrote in message
news:355B7331-25E9-4E98-BDC7-A7D8D9BC0C52@.microsoft.com...

Quote:

Originally Posted by

hey all,
what is the purpose of e.NewValues inside the GridView1_RowUpdating


routine?

Quote:

Originally Posted by

i've seen examples where you findControl then assign that value to
e.NewValues, but that seems like an extra step.

thanks,
rodchar


>
I use is to validate serverside. Here is an example
>
Sub EmailGrid_Updating(sender as object, e as GridViewUpdateEventargs)
'Check format of new data
dim bCancel as boolean = false
msg1.text = string.empty
dim strEmailAddress as string = string.empty
if not e.newvalues(0) is nothing then
strEmailAddress = Server.htmlencode(e.newvalues(0).tostring())
end if
BCancel= Regex.IsMatch(strEmailAddress,
"^([\w-\.]+)@.((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-
Z]{2,4}|[0-9]{1,3})(\]?)$")
if BCancel then
dim strDate as string = string.empty
if not e.newvalues(2) is nothing then
strDate = Server.htmlencode(e.newvalues(2).tostring())
BCancel = IsDate(strDate)
if BCancel then
if (year(ctype(strDate,datetime)) < 2000) then
BCancel = false
>
end if
if not bCancel then msg1.text = "Invalid Date"
end if
else
msg1.text = "Invalid Email Address"
end if
e.Cancel = not bCancel
End sub
>
>
>