Geekzone: technology news, blogs, forums
Guest
Welcome Guest.
You haven't logged in yet. If you don't have an account you can register now.




264 posts

Ultimate Geek
Inactive user


Topic # 49541 19-Nov-2009 15:42
Send private message

Hi Everyone,

I am creating a datagrid and I need the ability to add new rows to the database from this datagrid. I have placed textboxes in the footer of the datagrid and used an ItemCommand event handler so that when a linkbutton is clicked my function is called. Everything is going well except the text in the textboxes is not being passed properly to the function.

I am using the following command to extract the text.

sqlcmd.Parameters.Add("@GoodsDesc", SqlDbType.VarChar).Value = CType(e.Item.FindControl("txtGoodsDesc"), TextBox).Text

I'm sure this is right but I have a feeling the text is not being bound to the box or something as it is just giving me an empty string. Is there a step I am missing out here where I tell the code to set the text from the textboxes?

Create new topic
I'm @nate
6287 posts

Uber Geek
+1 received by user: 373

Moderator
Trusted
Subscriber

  Reply # 274576 19-Nov-2009 20:03
Send private message

What's happening in Page_load? Are you escaping that sub before your new line is initiated?




27 posts

Geek


  Reply # 274729 20-Nov-2009 13:10
Send private message

Hi there

Have you tried accessing the text box directly?

sqlcmd.Parameters.Add("@GoodsDesc", SqlDbType.VarChar).Value = Me.txtGoodsDesc.Text

This assumes the textbox's RunAtServer property is set to True.

Cheers

 
 
 
 


113 posts

Master Geek


  Reply # 274798 20-Nov-2009 18:34
Send private message

Hi, I use datagrids a lot in my development to display info, but I never wanted to use them for adding whole rows, instead I just setup some textboxes and combo boxes for the fields that I know are going to be there and then have a submit button, I find this makes it a little bit easier for the user to input data.

 

Hadley



264 posts

Ultimate Geek
Inactive user


  Reply # 275386 23-Nov-2009 10:14
Send private message

nate: What's happening in Page_load? Are you escaping that sub before your new line is initiated?


Thanks for the hint. It seems that when I click on the link to call the method it is going straight to page_load before it calls the function. This is causing it to clear the text boxes before it tries to read the text in them. Now it's just a matter of figuring out how to stop this. I have a few ideas so here's hoping it works.

27 posts

Geek


  Reply # 275398 23-Nov-2009 10:39
Send private message

Page.Load will be called for every post back. But by the time it is called (there is some code that runs prior to this) your textbox should already have its value. The only time that this may not happen is when you are dynamically adding controls with code, instead of using Asp.Net designer or the Html window. Post your code if you get stuck and I'll have a look.
Good luck
Cheers
Ben

3 posts

Wannabe Geek


  Reply # 280224 8-Dec-2009 02:21
Send private message

@OP:

Very important to remember not to re - bind data on page_load if a postback has occured you can use the following to assist you.


If page.isPostBack = false then
   'Call your databinding here
end if

Hope this helps :)

Create new topic



Twitter »

Follow us to receive Twitter updates when new discussions are posted in our forums:



Follow us to receive Twitter updates when news items and blogs are posted in our frontpage:



Follow us to receive Twitter updates when tech item prices are listed in our price comparison site:





News »

D-Link NZ launches professional Wireless AC Wave 2 Access Point for businesses
Posted 17-Aug-2017 19:25


Garmin introduces the Rino 700 five-watt two-way handheld radio
Posted 17-Aug-2017 19:04


Garmin announces the Foretrex 601 and Foretrex 701 Ballistic Edition for outdoor and tactical use
Posted 17-Aug-2017 19:02


Brightstar announces new distribution partnership with Samsung Knox platform in Australia
Posted 17-Aug-2017 17:07


Free gig-enabled WiFi network extends across Dunedin
Posted 17-Aug-2017 17:04


Samsung expands with connect Gear S3 Frontier
Posted 17-Aug-2017 15:55


Fact-checking Southern Cross Next cable is fastest to USA
Posted 17-Aug-2017 13:57


Thurrott says Microsoft Surface is dead last for reliability
Posted 16-Aug-2017 15:19


LibreOffice 5.4 works better with Microsoft Office files
Posted 16-Aug-2017 13:32


Certus launches Cognition
Posted 14-Aug-2017 09:31


Spark adds Cambridge, Turangi to 4.5G network
Posted 10-Aug-2017 17:55


REANNZ network to receive ongoing Government funding through to 2024
Posted 10-Aug-2017 16:05


Chorus backhaul starts with 2degrees
Posted 10-Aug-2017 15:49


New Zealanders cool on data analytics catching benefit fraud
Posted 10-Aug-2017 09:56


New Zealanders wary of wearable biometrics: Unisys
Posted 9-Aug-2017 09:39



Geekzone Live »

Try automatic live updates from Geekzone directly in your browser, without refreshing the page, with Geekzone Live now.



Are you subscribed to our RSS feed? You can download the latest headlines and summaries from our stories directly to your computer or smartphone by using a feed reader.

Alternatively, you can receive a daily email with Geekzone updates.