• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1589
  • Last Modified:

QueryString in FormView

I have this in my code behind:

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
        If Not Page.IsPostBack Then
            If Request.QueryString("Mode") = "Insert" Then
                ProjectView.DefaultMode = FormViewMode.Insert
            ElseIf Request.QueryString("Mode") = "Edit" Then
                ProjectView.DefaultMode = FormViewMode.Edit
            Else
                ProjectView.DefaultMode = FormViewMode.ReadOnly
            End If
        End If
    End Sub

I am trying to call the QueryString Mode from another page to direct to the Insert View of the page.  On this page, I have this:

       <SelectParameters>
          <asp:QueryStringParameter DefaultValue="0" name="SiteID" QueryStringField="SiteID" />
          <asp:QueryStringParameter DefaultValue="ReadOnly" name="Mode" type="String" />
        </SelectParameters>

<asp:FormView DefaultView="ReadOnly" id="ProjectView" DataSourceID="DataConnection"  Runat="Server"
  AllowPaging="False"
  GridLines="None"
  HeaderStyle-ForeColor="#FFFFFF"
  HeaderStyle-Font-Bold="True"
  HeaderStyle-HorizontalAlign="Center">


However, when I call the Page.aspx?Mode=Insert - the ProjectView (FormView) does not display.  Any ideas?

0
goodmanro
Asked:
goodmanro
  • 6
  • 4
1 Solution
 
ptleitchCommented:
try setting a default mode and then using the changemode command in your code

FormView1.ChangeMode(FormViewMode.Edit)
0
 
ptleitchCommented:
any luck?
0
 
bsdotnetCommented:
Currently, is ProjectView display readonly mode and blank?
a) please change DefaultView="ReadOnly" in your <asp:FormView> tag to DefaultMode=ReadOnly
b) do you have <InsertItem Template> section in your ProjectView?
       <asp:FormView DefaultMode=ReadOnly  id="ProjectView" ...>
            <EditItemTemplate>
               ...          
            </EditItemTemplate>
            <InsertItemTemplate>
                ...
            </InsertItemTemplate>
            <ItemTemplate>
                ...
            </ItemTemplate>
        </asp:FormView>
c) Lastly, when you view the page.aspx, make sure your url is .../Page.aspx?Mode=Insert
and the word "Insert" is case sensitve. "http://.../Page.aspx?Mode=insert" will NOT work.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
goodmanroAuthor Commented:
Ptleitch - I tried it, but no luck.

I tried:

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
        If Not Page.IsPostBack Then
            If Request.QueryString("Mode") = "Insert" Then
                'ProjectView.DefaultMode = FormViewMode.Insert
                ProjectView.ChangeMode(FormViewMode.Insert)
            ElseIf Request.QueryString("Mode") = "Edit" Then
                ProjectView.DefaultMode = FormViewMode.Edit
            Else
                ProjectView.DefaultMode = FormViewMode.ReadOnly
            End If
        End If


Bsdotnet - Yes, the FormView has an ItemTemplate, EditItemTemplate, and InsertItemTemplate.  The URL is also ProjectView.aspx?Mode=Insert (so its case sensitivity is correct).  I also changed DefaultView=ReadOnly.  Any other ideas?
0
 
ptleitchCommented:
i would recommend getting rid of the "ProjectView.DefaultMode = FormViewMode.Edit" altogether and replacing each and every one with the changemode command.  Define a default template, and anytime you want to change the mode to something else use changemode
0
 
goodmanroAuthor Commented:
So, I have this setup, but I'm still getting a blank FormView when I try to call ProjectView.aspx?Mode=Insert.  Technically, the QueryString variable should fire the ChangeMode Insert in this instance, but I'm not getting anything.  

 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
        If Not Page.IsPostBack Then
            If Request.QueryString("Mode") = "Insert" Then
                ProjectView.ChangeMode(FormViewMode.Insert)
            ElseIf Request.QueryString("Mode") = "Edit" Then
                ProjectView.ChangeMode(FormViewMode.Edit)
            Else
                ProjectView.ChangeMode(FormViewMode.ReadOnly)
            End If
        End If
    End Sub

Ideas?
0
 
ptleitchCommented:
sorry if this is a stupid question, but are all three of your templates configured?
0
 
goodmanroAuthor Commented:
Yes, I answered that above.

I have:

<asp:FormView DefaultView=ReadOnly id="ProjectView" DataSourceID="DataConnection"  Runat="Server"
  AllowPaging="False"
  GridLines="None"
  HeaderStyle-ForeColor="#FFFFFF"
  HeaderStyle-Font-Bold="True"
  HeaderStyle-HorizontalAlign="Center">  with the ItemTemplate, EditItemTemplate and InsertItemTemplate defined.  Order doesn't matter right?

Thanks!
0
 
ptleitchCommented:
try trouble shooting by eliminating the query string and just checking to see if your different templates appear on the page using no query string.  you could probably also try to pass the value to a session:

Session.Add("Mode", SomeControl)

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
If Session("Mode") = "Insert" Then
ProjectView.ChangeMode(FormViewMode.Insert)
ElseIf Session("Mode") = "Edit" Then
ProjectView.ChangeMode(FormViewMode.Edit)
Else
ProjectView.ChangeMode(FormViewMode.ReadOnly)
End If
End If
End Sub

when you call these values from session, you might have to do something like this
dim strMode as String = CType(Session("Mode"), String)
and then ust strMode for the comparison
If strMode = "Insert" Then
why don't you post your code between <edittemplate> and <itemtemplate>?
0
 
ptleitchCommented:
also page loads normally have this on the end:
Handles Me.Load

let me know if any of this helps
0
 
goodmanroAuthor Commented:
Ptleitch,
Thank you.  You were very helpful.  It always helps to have a second set of eyes.  I can't believe I missed that...

Thanks again -
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now