goodmanro
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="DataConnecti on" Runat="Server"
AllowPaging="False"
GridLines="None"
HeaderStyle-ForeColor="#FF FFFF"
HeaderStyle-Font-Bold="Tru e"
HeaderStyle-HorizontalAlig n="Center" >
However, when I call the Page.aspx?Mode=Insert - the ProjectView (FormView) does not display. Any ideas?
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
If Not Page.IsPostBack Then
If Request.QueryString("Mode"
ProjectView.DefaultMode = FormViewMode.Insert
ElseIf Request.QueryString("Mode"
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="DataConnecti
AllowPaging="False"
GridLines="None"
HeaderStyle-ForeColor="#FF
HeaderStyle-Font-Bold="Tru
HeaderStyle-HorizontalAlig
However, when I call the Page.aspx?Mode=Insert - the ProjectView (FormView) does not display. Any ideas?
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.
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.
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(For mViewMode. 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=Inse rt (so its case sensitivity is correct). I also changed DefaultView=ReadOnly. Any other ideas?
I tried:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
If Not Page.IsPostBack Then
If Request.QueryString("Mode"
'ProjectView.DefaultMode = FormViewMode.Insert
ProjectView.ChangeMode(For
ElseIf Request.QueryString("Mode"
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=Inse
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
ASKER
So, I have this setup, but I'm still getting a blank FormView when I try to call ProjectView.aspx?Mode=Inse rt. 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(For mViewMode. Insert)
ElseIf Request.QueryString("Mode" ) = "Edit" Then
ProjectView.ChangeMode(For mViewMode. Edit)
Else
ProjectView.ChangeMode(For mViewMode. ReadOnly)
End If
End If
End Sub
Ideas?
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
If Not Page.IsPostBack Then
If Request.QueryString("Mode"
ProjectView.ChangeMode(For
ElseIf Request.QueryString("Mode"
ProjectView.ChangeMode(For
Else
ProjectView.ChangeMode(For
End If
End If
End Sub
Ideas?
sorry if this is a stupid question, but are all three of your templates configured?
ASKER
Yes, I answered that above.
I have:
<asp:FormView DefaultView=ReadOnly id="ProjectView" DataSourceID="DataConnecti on" Runat="Server"
AllowPaging="False"
GridLines="None"
HeaderStyle-ForeColor="#FF FFFF"
HeaderStyle-Font-Bold="Tru e"
HeaderStyle-HorizontalAlig n="Center" > with the ItemTemplate, EditItemTemplate and InsertItemTemplate defined. Order doesn't matter right?
Thanks!
I have:
<asp:FormView DefaultView=ReadOnly id="ProjectView" DataSourceID="DataConnecti
AllowPaging="False"
GridLines="None"
HeaderStyle-ForeColor="#FF
HeaderStyle-Font-Bold="Tru
HeaderStyle-HorizontalAlig
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(For mViewMode. Insert)
ElseIf Session("Mode") = "Edit" Then
ProjectView.ChangeMode(For mViewMode. Edit)
Else
ProjectView.ChangeMode(For mViewMode. 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>?
Session.Add("Mode", SomeControl)
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
If Session("Mode") = "Insert" Then
ProjectView.ChangeMode(For
ElseIf Session("Mode") = "Edit" Then
ProjectView.ChangeMode(For
Else
ProjectView.ChangeMode(For
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
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
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 -
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 -
FormView1.ChangeMode(FormV