Link to home
Create AccountLog in
Avatar of goodmanro
goodmanroFlag for United States of America

asked on

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?

Avatar of ptleitch
ptleitch

try setting a default mode and then using the changemode command in your code

FormView1.ChangeMode(FormViewMode.Edit)
any luck?
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.
Avatar of goodmanro

ASKER

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?
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
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?
sorry if this is a stupid question, but are all three of your templates configured?
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!
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>?
ASKER CERTIFIED SOLUTION
Avatar of ptleitch
ptleitch

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
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 -