Geekzone: technology news, blogs, forums
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
6305 posts

Uber Geek
+1 received by user: 378

Lifetime 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


  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.



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.



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


  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

3 posts

Wannabe Geek

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


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 »

Stuff Pix enters streaming video market
Posted 21-Mar-2018 09:18

Windows no longer Microsoft’s main focus
Posted 13-Mar-2018 07:47

Why phone makers are obsessed with cameras
Posted 11-Mar-2018 12:25

New Zealand Adopts International Open Data Charter
Posted 3-Mar-2018 12:48

Shipments tumble as NZ phone upgrades slow
Posted 2-Mar-2018 11:48

Oppo R11s: high-end Android, budget price
Posted 27-Feb-2018 16:27

Samsung New Zealand introducing the Galaxy S9 and S9+
Posted 26-Feb-2018 07:00

Fujifilm X beats its best with new top of the range, high-performance camera
Posted 24-Feb-2018 14:05

One million kiwis affected by cybercrime
Posted 24-Feb-2018 13:58

New Zealanders want to engage with government online and via mobile apps
Posted 24-Feb-2018 13:56

Samsung launches Samsung Max
Posted 24-Feb-2018 13:52

CPTPP text and National Interest Analysis released for public scrutiny
Posted 21-Feb-2018 19:43

Foodstuffs to trial digitised shopping trolleys
Posted 21-Feb-2018 18:27

2018: The year of zero-login, smart cars & the biometrics of things
Posted 21-Feb-2018 18:25

Intel reimagines data centre storage with new 3D NAND SSDs
Posted 16-Feb-2018 15:21

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.