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

Uber Geek
+1 received by user: 377

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 »

Mobile market competition issues ComCom should watch
Posted 18-Dec-2017 10:52


New Zealand government to create digital advisory group
Posted 16-Dec-2017 08:47


Australia datum changes means whole country moving 1.8 metres north-east
Posted 16-Dec-2017 08:39


UAV Traffic Management Trial launching today in New Zealand
Posted 12-Dec-2017 16:06


UFB connections pass 460,000
Posted 11-Dec-2017 11:26


The Warehouse Group to adopt IBM Cloud to support digital transformation
Posted 11-Dec-2017 11:22


Dimension Data peeks into digital business 2018
Posted 11-Dec-2017 10:55


2018 Cyber Security Predictions
Posted 7-Dec-2017 14:55


Global Govtech Accelerator to drive public sector innovation in Wellington
Posted 7-Dec-2017 11:21


Stuff Pix media strategy a new direction
Posted 7-Dec-2017 09:37


Digital transformation is dead
Posted 7-Dec-2017 09:31


Fake news and cyber security
Posted 7-Dec-2017 09:27


Dimension Data New Zealand strengthens cybersecurity practice
Posted 5-Dec-2017 20:27


Epson NZ launches new Expression Premium Photo range
Posted 5-Dec-2017 20:26


Eventbrite and Twickets launch integration partnership in Australia and New Zealand
Posted 5-Dec-2017 20:23



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.