[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Trying to load a asp:textbox with a querystring value in a listbox

Posted on 2012-09-06
8
Medium Priority
?
444 Views
Last Modified: 2012-09-15
Here is the scenario.

Page #1 passes the following string below to page #2:

http://localhost:4659/SPMasterDetail.aspx?strategyid=1.1

I need the strategyid to populate the stratedyid textbox in ListView20.  The user will fill out the rest of the textboxes in the insert form and submit to update the database table.

Please see attached text file with the code.
querystringissue.txt
0
Comment
Question by:rjkissinger
  • 4
  • 2
  • 2
8 Comments
 
LVL 23

Expert Comment

by:Christopher Kile
ID: 38374360
Perhaps you should assign a type to the QueryStringParameter:

<asp:QueryStringParameter Name="StrategyID" type="string" QueryStringField="strategyid" />

I'm assuming string is the appropriate type in this case.
0
 

Author Comment

by:rjkissinger
ID: 38374502
I made this modification and it didn't solve the issue.  I double checked the case and it matches.
0
 
LVL 26

Expert Comment

by:Alan Warren
ID: 38374802
Maybe something like this could do the trick:
  Private Sub ListView20_ItemCreated(ByVal sender As Object, ByVal e As ListViewItemEventArgs)
    ' If e.Item.ItemType = ListViewItemType.DataItem Then
    If e.Item.ItemType = ListViewItemType.InsertItem Then
      Dim currentItem As ListViewDataItem = CType(e.Item, ListViewDataItem)
      Dim objTextBox As TextBox = CType(currentItem.FindControl("StrategyIDTextBox"), TextBox)
      If objTextBox IsNot Nothing Then
        With objTextBox
          If Context.Request.QueryString("strategyid") IsNot Nothing Then
            .Text = Context.Request.QueryString("strategyid")
          End If
        End With
      End If
    End If
  End Sub

Open in new window

Alan
0
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

 

Author Comment

by:rjkissinger
ID: 38376159
This doesn't appear to work either.  I was able to add an asp:detailsview1 as a test and got the stratedyid to load in  textbox1.  I still can't figure out why I can't load a textbox with the strategyid in listview20 in the InsertItemTemplate.  I've attached all my code.
detailpage.txt
0
 
LVL 26

Expert Comment

by:Alan Warren
ID: 38378244
Your page_load event may be overwriting it.

Put a breakpoint on the following line and step through the code (F11) a line at a time to see if the control is found and populated:
If e.Item.ItemType = ListViewItemType.InsertItem Then

Also noticed you have AutoEventWireUp="false" in your page directive, in which case you may need to add an OnItemCreated="ListView20_ItemCreated" to your listview definition, or the event may not be firing.

Alan
0
 

Accepted Solution

by:
rjkissinger earned 0 total points
ID: 38384541
I couldn't get this to work until I created a OnPreRender Sub.  This solved the problem and the textbox is now loaded with the desired value for inserting a new record into the database.  Thanks for you help.  I've included the code below for others to use.


       <asp:ListView ID="ListView20" runat="server" DataKeyNames="TacticID"
                  OnPreRender="ListView20_OnPreRender"  DataSourceID="StrategiesColumn2" InsertItemPosition="LastItem">

Protected Sub ListView20_OnPreRender(ByVal sender As Object, ByVal e As EventArgs)
        ListView20.DataBind()
        DirectCast(ListView20.InsertItem.FindControl("StrategyIDTextbox"), TextBox).Text =    Request.QueryString("strategyid")
    End Sub
0
 
LVL 23

Expert Comment

by:Christopher Kile
ID: 38384604
rjkissinger,

Congratulations, and thanks for posting your solution.  Solve someone else's problem and get some points for it :D
0
 

Author Closing Comment

by:rjkissinger
ID: 38401344
Through additional research I found the solution that solved the problem.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Loops Section Overview

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question