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
6291 posts

Uber Geek
+1 received by user: 375

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 »

Vodafone TV — television in the cloud
Posted 17-Oct-2017 19:29


Nokia 8 review: Classy midrange pure Android phone
Posted 16-Oct-2017 07:27


Why carriers might want to embrace Commerce Commission study, MVNOs
Posted 13-Oct-2017 09:42


Fitbit launches Ionic, its health and fitness smartwatch
Posted 12-Oct-2017 15:52


Xero launches machine learning automation to improve coding accuracy for small businesses
Posted 12-Oct-2017 15:45


Bank of New Zealand uses Intel AI to detect financial crime
Posted 12-Oct-2017 15:39


Sony launches Xperia XZ1, a smartphone with real-time 3D capture
Posted 11-Oct-2017 10:26


Notes on Nokia’s phone comeback
Posted 10-Oct-2017 10:06


Air New Zealand begins Inflight Wi-Fi rollout
Posted 9-Oct-2017 20:16


The latest mobile phones in perspective
Posted 9-Oct-2017 18:34


Review: Acronis True Image 2018 — serious backup
Posted 8-Oct-2017 11:22


Lenovo launches ThinkPad Anniversary Edition 25
Posted 7-Oct-2017 23:16


Less fone, more tech as Vodafone gets brand make-over
Posted 6-Oct-2017 08:16


API Talent Achieves AWS MSP Partner Status
Posted 5-Oct-2017 21:20


Stellar Consulting Group now a Domo Partner
Posted 5-Oct-2017 21:03



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.