Nested Datalists using stored procedure parameters - stored-procedures

I'm working with some nested datalist controls and cannot get the SP parameters for my nested stored procedure to work.
In debug I can see that SqlDataSource2.SelectParameters.Add("Section",oLabel.Text.ToString()); is getting the correct value from the label but when the results display I always get the results for the last parameter added?
I'm guessing I need to clear the parameters in some way each time the nested datalist is bound but if I add code to do that it results in an error that I have not specified the parameters?
My code is below, you'll see that eventually I will have 3 nested datalists inside each other - or that's the plan.
Thanks for any suggestions
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="nhscsharprepeater._Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%# Import Namespace="System.Web" %>
<%# Import Namespace="System.Web.UI" %>
<%# Import Namespace="System.Data" %>
<script type="text/C#" runat="server">
protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
{
DataList oList = (DataList)e.Item.FindControl("Datalist2");
Label oLabel = (Label)e.Item.FindControl("lblSection");
DataList oList2 = (DataList)oList.FindControl("Datalist3");
SqlDataSource2.SelectParameters.Clear();
SqlDataSource2.SelectCommand = "report_DistinctSubSections";
SqlDataSource2.SelectParameters.Add("Section",oLabel.Text.ToString());
oList.DataBind();
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:productfolioConnectionString %>"
SelectCommand="report_DistinctSection" SelectCommandType="StoredProcedure"></asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:productfolioConnectionString %>"
SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:Parameter Name="Section" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:productfolioConnectionString %>"
SelectCommand="report_getReports" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:Parameter Name="SubSection" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
<asp:DataList ID="DataList1" runat="server" DataSourceID="SqlDataSource1" RepeatColumns="2" RepeatDirection="Horizontal" OnItemDataBound="DataList1_ItemDataBound">
<ItemTemplate>
<asp:Label Runat="server" text='<%# DataBinder.Eval(Container.DataItem, "Section") %>' ID="lblSection">
</asp:Label>
<br />
<asp:datalist id="Datalist2" runat="server" DataSourceID="SqlDataSource2">
<ItemTemplate>
<asp:Label Runat="server" text='<%# DataBinder.Eval(Container.DataItem, "SubSection") %>' ID="lblSection">
</asp:Label>
<br />
<asp:datalist id="Datalist3" runat="server" DataSourceID="SqlDataSource3">
<ItemTemplate>
<!--<asp:Label Runat="server" text='<%# DataBinder.Eval(Container.DataItem, "Report") %>' ID="lblSection">
</asp:Label>-->
</ItemTemplate>
</asp:datalist>
</ItemTemplate>
</asp:datalist>
</ItemTemplate>
</asp:DataList>
</div>
</form>
</body>
</html>

One might guess that calling Clear on SqlDataSource2.SelectParameters before calling Add might do the trick.

Related

CSS Float Right not working on ios Tablet

I am having some issue with float right on an iOS tablet. The css for this works on a desktop. The issue is that the elements contained within this div don't float to the extreme right. They go about 2 thirds of the way.
The body, form, and div in the master file are all width=100%
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<div class="FloatRight" style="padding-left: 20px; width:600px;margin:0 0 0 0;" >
<asp:TextBox ID="FeedbackNoteTB" Width="500px" Rows="5" TextMode="MultiLine" runat="server" Height="100px"/><br />
<asp:Label runat="server" ID="Label1" Text="Include In Meeting" Font-Size="X-Large"></asp:Label> <asp:CheckBox runat="server" ID="IncludeInMeetingCB" Checked="true" class="big-checkbox" CssClass="big-checkbox" /><br />
<asp:Button CssClass="btn-primary btn-lg btn-block" runat="server" Text="Save" ID="SaveFeedbackNoteBTN" OnClick="SaveFeedbackNoteBTN_Click" />
<br />
<asp:GridView runat="server" ID="MarketFeedbackQuestions" DataSourceID="MarketFeedbackQuestionsDS" AutoGenerateColumns="False" >
<RowStyle CssClass="RowStyle" />
<AlternatingRowStyle CssClass="alt" />
<Columns>
<asp:TemplateField HeaderText="Question" SortExpression="Question">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" CssClass="textbox" Text='<%# Bind("Question") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("Question") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Answer" SortExpression="Answer">
<EditItemTemplate>
<asp:TextBox ID="TextBox3" runat="server" CssClass="textbox" Text='<%# Bind("Answer") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("Answer") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="DateQuestionAnswered" SortExpression="DateQuestionAnswered">
<EditItemTemplate>
<asp:TextBox ID="TextBox4" runat="server" CssClass="textbox" Text='<%# Bind("DateQuestionAnswered") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%# Bind("DateQuestionAnswered") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:SqlDataSource runat="server" ID="MarketFeedbackQuestionsDS" ConnectionString="<%$ ConnectionStrings:XXXXXXXXXXXXX %>" SelectCommand="SELECT MarketFeedbackAnswerID,mfq.MarketFeedbackQuestionID,Answer,CustomerID,DateQuestionAnswered,Question,[Order] FROM XXXXXXXX mfq LEFT JOIN XXXXxXXX mfa ON mfq.MarketFeedbackQuestionID = mfa.MarketFeedbackQuestionID WHERE CustomerID = #CustomerID AND (DateQuestionAnswered > DATEADD(day,-7,GetDate()) OR DateQuestionAnswered IS NULL)" >
<SelectParameters>
<asp:QueryStringParameter Name="CustomerID" QueryStringField="cid" />
</SelectParameters>
</asp:SqlDataSource>
</div>
The css FloatRight class is as follows.
.FloatRight {
float: right;
}
Does anybody know how to get my div to float to the complete right?
Try by placing !important at last of CSS property like:
.FloatRight {
float: right !important;
}
If it doesn't work try to open it in Private window because the private window doesn't collect the cache
OR
You can use the media query for the specific device

Different behavior on click of two buttons on same page in Struts 2

I have test.jsp which has two buttons.on click of Display Chart button,it should open chart on new page which is happening using target=_blank in form tag. But problem is i don't want this behavior on click of Display Data button. On click of this button,I want to display data fetched on same page only,but currently for this button as well it is opening a new window .
My code is:
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%# taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Data</title>
<s:head theme="ajax" debug="true"/>
</head>
<body bgcolor="white">
<s:form validate="true" target="_blank">
<table>
//Mapping of data from database
</table>
<s:submit id="submit" value="Display Chart" align="left" action="testAction"/>
<s:submit value="Display Data" align="left" action="displayDataAction"/>`
</s:form>
</body>
</html>
public class TestAction extends ActionSupport{
public String execute() throws Exception {
//code to populate DataSet
chart = ChartFactory.createBarChart(
"Bar Chart", //Chart title
"", //Domain axis label
"MARKETS", //Range axis label
dataSet, //Chart Data
PlotOrientation.VERTICAL, // orientation
true, // include legend?
true, // include tooltips?
false // include URLs?
);
chart.setBorderVisible(true);
return SUCCESS;
}
}
struts.xml:
<action name="testAction"
class="testAction"
method="execute">
<result name="success" type="chart">
<param name="value">chart</param>
<param name="type">jpeg</param>
<param name="width">600</param>
<param name="height">400</param>
</result>
</action>
<action name="displayDataAction"
class="testAction"
method="getData">
<result name="success">test.jsp</result>
</action>
I got it done as follows :
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%# taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script type="text/javascript">
function openPopUp(){
document.getElementById('testForm').setAttribute('target', '_blank');
document.getElementById('testForm').setAttribute('action', 'testAction.action');
document.getElementById('testForm').submit();
}
function noPopUp(){
document.getElementById('testForm').setAttribute('target', '');
}
<title>Data</title>
<s:head theme="ajax" debug="true"/>
</head>
<body bgcolor="white">
<s:form validate="true" target="_blank">
<table>
//Mapping of data from database
</table>
<s:submit id="submit" value="Display Chart" align="left" onclick="openPopUp();"/>
<s:submit value="Display Data" align="left" action="displayDataAction" onclick="noPopUp();"/>`
</s:form>
</body>
</html>

My ActionClass in not getting called

I want to fetch a text box value from jsp to my action class.
But my action class in not getting called while submitting the page.
My code are
Jsp page
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<form action="AddedColor" method="post">
<div class="box">
<span class="label">Color Name</span>
<span class="ib"> <input type="text" name="color" id="color"/></span>
</div>
<div class="box">
<input type="button" id="submit_color" value="Add Color"/>
</div>
</form>
</body>
</html>
In struts.xml
<package name="colorpkg" extends="struts-default">
<action name="AddedColor" class="iland.work.ColorAction" method="insert">
<result name="success">/pages/colors/showColors.jsp</result>
</action>
</package>
In ActionClass
public class ColorAction extends ActionSupport {
private String color;
//getter and setter of color
public String insert() {
System.out.println("-> ColorAction insert()");
System.out.println(getColor());
return SUCCESS;
}
}
try this:
<div class="box">
<input type="submit" id="submit_color" value="Add Color"/>
</div>

How can i shrink my web page to fit in mobile

I am using asp.net web forms for developing mobile application
My Code:
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="MobileApplication.Default" %>
<!DOCTYPE html>
<html>
<head id="Head1" runat="server">
<title>Mobile WebForms</title>
<meta charset="urf-8" />
<meta name="viewport" content="width=device-width" />
<style type="text/css">
body
{
font-family:Verdana;
height: 119px;
}
label
{
font-size:11pt;
font-family: Arial, Helvetica, sans-serif;
display:block;
margin-right:50px;
}
input[type=text]
{
width:200px;
height:15px;
margin-left:15px
}
.content
{
width:350px;
margin:0px auto;
}
header
{
width:350px;
text-align:center;
font-size:15px;
font-weight:bold;
}
.button
{
width:350px;
text-align:center;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div data-role="content">
<asp:Table ID="Table1" runat="server" GridLines="Both" Height="107px" Width="210px">
<asp:TableRow runat="server">
<asp:TableCell runat="server">
<asp:Label ID="Label1" runat="server" Text="Request ID"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server" Text="9015/DOM/NDA/0711"></asp:TextBox>
</asp:TableCell>
<asp:TableCell runat="server">
<asp:Label ID="Label2" runat="server" Text="Request Type" ></asp:Label>
<asp:TextBox ID="TextBox2" runat="server" Text="Domestic Travel - Self (Employee)"></asp:TextBox>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow runat="server">
<asp:TableCell runat="server">
<asp:Label ID="Label3" runat="server" Text="Request Status"></asp:Label>
<asp:TextBox ID="TextBox3" runat="server" Text="Pending With L1 Manager"></asp:TextBox>
</asp:TableCell>
<asp:TableCell runat="server">
<asp:Label ID="Label4" runat="server" Text="Label"></asp:Label>
<asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
</asp:TableCell>
</asp:TableRow>
</asp:Table>
</div>
</form>
</body>
</html>
I am getting below output in emulator but I want my page to shrink and fit in mobile display.
My web page output is:
This output should shrink and fit into mobile.I have used viewport tag to do this but I am not getting the desired output. Please help me to do this task. Is iquery mobile helpful in doing this?
There are many combination you can use, i would suggest below one,
1) use this viewport tag, <meta name="viewport" content = "width =device-width, initial-scale = 1.0, maximum-scale = 1.0, user-scalable = no"/>
2) Use a fluid layout, twitter bootstrap is a good library

issue with fileUpload in MVC if site.master contains <scriptmanager>

iam working on fileUpload in mvc.
my code is as follows:
Views/Client/AddClient.aspx
<%# Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<Auditz.UI.Web.Automation.ClientService.ClientDto>" %>
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<h1>
Add A Client</h1>
<% using (Html.BeginForm("AddClient","Client",FormMethod.Post,new {enctype = "multipart/form-data" }))
{ %>
<%: Html.ValidationSummary(true) %>
<div class="tabcontrol">
<asp:Panel ID="pnlClientDtls" runat="server">
<asp:TabContainer ID="TabContainer" runat="server" Width="100%" ActiveTabIndex="1">
<asp:TabPanel ID="tb1" runat="server">
<HeaderTemplate>
Client Details
</HeaderTemplate>
<ContentTemplate>
<div class="formelements">
.....................
..............
</div>
Controllers/FileUploadController.cs
namespace FileUploadTest.Controllers
{
public class FileUploadController : Controller
{
//
// GET: /FileUpload/
public ActionResult FileUpload()
{
return View();
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult FileUpload(HttpPostedFileBase uploadFile)
{
if (uploadFile.ContentLength > 0)
{
string filePath = Path.Combine(HttpContext.Server.MapPath("~/Uploads"),
Path.GetFileName(uploadFile.FileName));
uploadFile.SaveAs(filePath);
}
return View();
}
}
}
Evrything works as desired with this code.
But if i place and in of Shared/Site.Master,iam getting null value in "HttpPostedFileBase uploadFile".
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
</form>
<div>
<asp:ContentPlaceHolder ID="MainContent" runat="server">
</asp:ContentPlaceHolder>
</div>
i cannot remove from my code as i want to add few ajax controls.
Make sure that you don't nest HTML forms. So in your Master page when you open the <form> tag ensure that you close it before rendering the view:
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
</form>
...
<asp:ContentPlaceHolder ID="MainContent" runat="server" />
</body>

Resources