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 »

How Oppo shakes New Zealand’s phone market
Posted 22-Aug-2017 18:32


Recognition for top small business advisors
Posted 22-Aug-2017 17:23


OPPO R11 dual 20MP camera phone debuts in New Zealand
Posted 22-Aug-2017 15:45


Intel introduces new 8th Generation processors
Posted 21-Aug-2017 19:02


Trend Micro launches Home Network Security
Posted 21-Aug-2017 18:38


Avondale College students at top of Microsoft Office Specialist World Championship
Posted 21-Aug-2017 14:11


Garmin introduces inReach SE+ and inReach Explorer+
Posted 21-Aug-2017 14:05


Public Wi-Fi plus cloud file sharing
Posted 18-Aug-2017 11:20


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



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.