Currently i have a Detail View table that automaticly opens in Insert Mode. The fields that are in there i linked to a database where the customer has to put in their information.
I want to add new fields that are read only that contain a Session State value from a previous page but can also be posted to the database. The customer can not add this in manualy, so needs to be done dynamicly.
From the previous page this is how the state variable is passed:
Would the Submit button on he Detail View post the field? if i put the ID in the Insert Command? also i dont want it to be hidden just a read only. Would a label work just as well?
You should be able to POST the field - you will just need to make sure that the Name / ID fields match that of what you are expecting. You should have no problem using a Textbox or Label field as well, both of which you should be able to set to Read-only.
This and tusharr's suggestions should both work for what you need to do.
Hi Ive tried both of your suggestions but i cant get the Session value to show in the label still. theres no errors but its not showing. I can get it to display outside the detail view. just dosent want to show in the detial view?
Thanks! Managed to get the sessions be be displayed. Now im stumped on inserting the data from the detail view to two different database tabels? it wont let me have more them one insert commands?
Hi, first, the database should contains a column to store the Session State value, otherwise, it will give an error message when inserting. I assume your database contains a column named “StartDate” as other columns: “Customer_ID”, “First_Name”… Second,
your data source “SqlDataSource1” should enable “InsertCommand”. After that, you can modify your markup as:
I recently came accross the Asp.Net Web Profiler. It is really handy when looking at what goes on in your web application memory. It shows an entire break down of the cache, application state and all active sessions. It shows all the sizes of everything
in memory and has some drill down functionality to explore all the data and its properties. You can download it from
http://www.aspwebprofiler.com
antonyjfento...
0 Points
10 Posts
Display an Session State Value Within a Detail View
Apr 16, 2012 05:12 PM|LINK
Hi Everyone,
Currently i have a Detail View table that automaticly opens in Insert Mode. The fields that are in there i linked to a database where the customer has to put in their information.
I want to add new fields that are read only that contain a Session State value from a previous page but can also be posted to the database. The customer can not add this in manualy, so needs to be done dynamicly.
From the previous page this is how the state variable is passed:
protected void Button_Click(object sender, EventArgs e) { Session["StartDate"] = StartDate.Text; Session["EndDate"] = EndDate.Text;Response.Redirect("Customer.aspx");}
This is the detials view:
Any ideas on the best way to approach this?
Thanks
Aj
DetailsView sessionstate
Rion William...
All-Star
27364 Points
4542 Posts
Re: Display an Session State Value Within a Detail View
Apr 16, 2012 05:28 PM|LINK
You could place them in HiddenField variables - so that they could be accessed during the POST operation. The syntax would be something like:
You will need to perform some null-checking as well on these fields - otherwise you might get a null reference exception.
antonyjfento...
0 Points
10 Posts
Re: Display an Session State Value Within a Detail View
Apr 16, 2012 05:51 PM|LINK
Hey Rion
Would the Submit button on he Detail View post the field? if i put the ID in the Insert Command? also i dont want it to be hidden just a read only. Would a label work just as well?
Thanks
tusharrs
Contributor
3230 Points
668 Posts
Re: Display an Session State Value Within a Detail View
Apr 16, 2012 06:04 PM|LINK
Hi,
You can directly add a sessionparameter to the sqldatasource1 like this
<asp:SqlDataSource ...>
<SelectParameters>
<asp:SessionParameter Name="spstartdate" SessionField="startdate"
/>
...
</SelectParameters>
</asp:SqlDataSource>
OR
put a template field in detailsview
insert a textbox in the template field
<asp:TemplateField>
<ItemTemplate>
<asp:TextBox ID="txtstartdate" runat="server" Text='<%# Session["startdate"] %>' Readonly="true"/>
<asp:TextBox ID="txtenddate" runat="server" Text='<%# Session["enddate"] %>' Readonly="true"/>
</ItemTemplate>
</asp:TemplateField>
And use this to insert in the database
<SelectParameters>
<asp:SessionParameter Name="startdate" SessionField="startdate" Type="DateTIme" />
<asp:SessionParameter Name="enddate" SessionField="enddate" Type="DateTime" />
</SelectParameters>
</asp:SqlDataSource>
( Mark as Answer if it helps you out )
View my Blog
Rion William...
All-Star
27364 Points
4542 Posts
Re: Display an Session State Value Within a Detail View
Apr 16, 2012 08:43 PM|LINK
@antony,
You should be able to POST the field - you will just need to make sure that the Name / ID fields match that of what you are expecting. You should have no problem using a Textbox or Label field as well, both of which you should be able to set to Read-only.
This and tusharr's suggestions should both work for what you need to do.
antonyjfento...
0 Points
10 Posts
Re: Display an Session State Value Within a Detail View
Apr 17, 2012 12:30 PM|LINK
Hi Ive tried both of your suggestions but i cant get the Session value to show in the label still. theres no errors but its not showing. I can get it to display outside the detail view. just dosent want to show in the detial view?
<asp:TemplateField HeaderText=" Start Date"> <ItemTemplate> <asp:Label ID="txtstartdate" runat="server" Text='<%# Session["StartDate"] %>' Value='<%# Session["StartDate"] %>' Readonly="true"/> </ItemTemplate> </asp:TemplateField> <asp:CommandField ButtonType="Button" CancelText="" InsertText="Continue" NewText="" SelectText="" ShowCancelButton="False" ShowInsertButton="True" UpdateText="" /> </Fields> <FooterStyle BackColor="#d40242" ForeColor="Black" /> <HeaderStyle BackColor="#d40242" Font-Bold="True" ForeColor="#d40242" /> <PagerStyle BackColor="#d40242" ForeColor="Black" HorizontalAlign="Right" /> </asp:DetailsView> <asp:SqlDataSource runat="server"> <SelectParameters> <asp:SessionParameter Name="startdateses" SessionField="StartDate" Type="DateTIme" /> </SelectParameters> </asp:SqlDataSource>tusharrs
Contributor
3230 Points
668 Posts
Re: Display an Session State Value Within a Detail View
Apr 17, 2012 12:40 PM|LINK
Hi,
check the value of session variable in code behind using a break point
and see if it shows the expected values or it is null or empty
you can check in the watch window
suppose the session variable is startdate then you can check for
Session["startdate"] in watch window
( Mark as Answer if it helps you out )
View my Blog
antonyjfento...
0 Points
10 Posts
Re: Display an Session State Value Within a Detail View
Apr 17, 2012 08:13 PM|LINK
Thanks! Managed to get the sessions be be displayed. Now im stumped on inserting the data from the detail view to two different database tabels? it wont let me have more them one insert commands?
Allen Li - M...
Star
10411 Points
1196 Posts
Re: Display an Session State Value Within a Detail View
Apr 18, 2012 06:28 AM|LINK
Hi, first, the database should contains a column to store the Session State value, otherwise, it will give an error message when inserting. I assume your database contains a column named “StartDate” as other columns: “Customer_ID”, “First_Name”… Second, your data source “SqlDataSource1” should enable “InsertCommand”. After that, you can modify your markup as:
<asp:DetailsView ID="DetailsView2" runat="server" Height="50px" Width="125px" AutoGenerateRows="False" DataKeyNames="Customer_ID" DataSourceID="SqlDataSource1" BackColor="#D40242" BorderColor="#D40242" BorderStyle="None" BorderWidth="1px" CellPadding="4" ForeColor="Black" GridLines="Horizontal" Style="font-family: Arial, Helvetica, sans-serif; font-size: small"> <EditRowStyle BackColor="#d40242" Font-Bold="True" ForeColor="White" /> <Fields> <asp:BoundField DataField="Customer_ID" HeaderText="Customer ID" InsertVisible="False" ReadOnly="True" SortExpression="Customer_ID" Visible="False" /> <asp:BoundField DataField="First_Name" HeaderText="First Name" SortExpression="First_Name" /> <asp:BoundField DataField="Last_Name" HeaderText="Last Name" SortExpression="Last_Name" /> <asp:BoundField DataField="Post_Code" HeaderText="Post_Code" SortExpression="Post_Code" /> <asp:BoundField DataField="House_Number_Name" HeaderText="House Name/Number" SortExpression="House_Number_Name" /> <asp:BoundField DataField="Street" HeaderText="Street" SortExpression="Street" /> <asp:BoundField DataField="City_Town" HeaderText="City Town" SortExpression="City_Town" /> <asp:BoundField DataField="County" HeaderText="County" SortExpression="County" /> <asp:BoundField DataField="Contact_No" HeaderText="Contact No" SortExpression="Contact_No" /> <!-- The Session field: --> <asp:TemplateField HeaderText="StartDate"> <ItemTemplate> <%# Eval("StartDate")%></ItemTemplate> <InsertItemTemplate> <asp:TextBox ID="Session" runat="server" ReadOnly="true" Text='<%# Bind("StartDate") %>' OnLoad="SetDefaultValues"></asp:TextBox> </InsertItemTemplate> </asp:TemplateField> <asp:CommandField ButtonType="Button" CancelText="" InsertText="Continue" NewText="" SelectText="" ShowCancelButton="False" ShowInsertButton="True" UpdateText="" /> </Fields> <FooterStyle BackColor="#d40242" ForeColor="Black" /> <HeaderStyle BackColor="#d40242" Font-Bold="True" ForeColor="#d40242" /> <PagerStyle BackColor="#d40242" ForeColor="Black" HorizontalAlign="Right" /> </asp:DetailsView>Then please add the following method to your C# codes:
protected void SetDefaultValues(object sender, EventArgs e) { TextBox newValue = (TextBox)DetailsView1.FindControl("StartDate"); newValue.Text = Session["StartDate"]; }If you have any feedback about my replies, please contact msdnmg@microsoft.com
Microsoft One Code Framework
MiasVanDenBe...
Member
6 Points
2 Posts
Re: Display an Session State Value Within a Detail View
Nov 04, 2012 06:01 PM|LINK
I recently came accross the Asp.Net Web Profiler. It is really handy when looking at what goes on in your web application memory. It shows an entire break down of the cache, application state and all active sessions. It shows all the sizes of everything in memory and has some drill down functionality to explore all the data and its properties. You can download it from http://www.aspwebprofiler.com
ApplicationState DetailsView sessionstate drilldown cache