|
|
Hi Gurus,
We have an online ballot app that has a bunch of radioButtonList with values dynamically populated from the database.
Please see screenshots below to see example ballot
Sample ballot
All values ( Candidate A, Candidate B, Write In Candidate) are all stored on the database dynamically populate the radioButtonList.
Example 1 shows the current setup.
How do I modify my script to have setup similar to example2?
Here is the code I am working with so far:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Online Ballot</title>
<meta http-equiv="X-UA-Compatible" content="IE=7, IE=8, IE=9, IE=10, IE=11" />
<meta name="DownloadOptions" content="noopen" />
<link rel="Stylesheet" href=
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script type = "text/javascript">
function validateCheckBoxList(source, args) {
var chkListModules = $(source).parent().find("table[id$='_CheckBoxList1']");
if (chkListModules.length == 0 || chkListModules.find(
args.IsValid = true;
else
args.IsValid = false;
}
</script>
<script type="text/javascript">
function show(ctr) {
var tb = document.getElementById("TextBox1");
if (ctr == "RadioButtonList1") {
tb.style.display = "block";
}
else
tb.style.display = "none";
}
</script>
<style type="text/css">
fieldset { border:1px solid red }
legend {
padding: 0.2em 0.5em;
border:1px solid red;
color:green;
}
</style>
</head>
<body background="images/bg.gif">
<form id="form1" runat="server">
<table bgcolor="#003366" width="100%">
<tr><td><img src="images/ballotslogo.png" alt="" /></td></tr></table>
<div id=
<div class=
</div></div>
</div>
<div id=
<div id=
<div id=
<div id=
<div class=
<div style="position:absolute; left:170px; top:206px; z-index:800;">
<div align="center">
<asp:Panel ID="Panel1" runat="server" GroupingText="" BorderColor="#999999" Width="100%" Font-Size="14pt">
<fieldset style="margin-bottom: 20px;">
<legend style="font-weight: bold;">DECISION 2014 - CLOSING DATE: MARCH 21, 2014 @ 5:00PM</legend>
<table style="width: 100%">
<tr>
<td>
<asp:DataList ID="DataList1" runat="server" DataKeyNames="ElectionId"
DataSourceID="SqlDataSource1" Width="100%" CellPadding="3"
BackColor="White" BorderColor="#999999" BorderStyle="None" BorderWidth="0px"
GridLines="Vertical">
<ItemStyle BackColor="#EEEEEE" ForeColor="Black" />
<ItemTemplate>
<table style="width: 100%;">
<tr>
<td style="text-align: center;">
<asp:Label ID="Label2" runat="server" Font-Bold="True" Font-Size="X-Large"
Text=
<asp:Label ID="lbl_MessageType" runat="server" ForeColor="red" Text=
</td>
</tr>
<tr>
<td style="text-align: left;">
<div id="buttonDiv" runat="server">
<asp:RadioButtonList ID="RadioButtonList1" runat="server" AutoPostBack="true" align="center" style="width:20px;height:20px;zoom:120%; white-space:nowrap;">
</asp:RadioButtonList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" Runat="server"
ControlToValidate="RadioButtonList1" ForeColor="Red" Display="Dynamic" ErrorMessage="Required"></asp:RequiredFieldValidator>
</div>
<asp:CheckBoxList ID="CheckBoxList1" runat="server" align="center" style="width:20px;height:20px;zoom:120%; white-space:nowrap;">
</asp:CheckBoxList>
<hr />
<asp:CustomValidator ID="CustomValidator1" runat="server"
ClientValidationFunction="validateCheckBoxList" Display="static"
ErrorMessage="Please select at least one box." ForeColor="Red"></asp:CustomValidator>
<asp:TextBox ID="TextBox1" runat="server" Columns="30" Font-Bold="False"
Rows="5" TextMode="MultiLine" Visible="false"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" Runat="server"
ControlToValidate="TextBox1" Display="Dynamic" ErrorMessage="Required"></asp:RequiredFieldValidator>
</td>
</tr>
</table>
<asp:HiddenField ID="HiddenField1" runat="server"
Value=
<asp:HiddenField ID="HiddenField2" runat="server"
Value=
</ItemTemplate>
<HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />
<HeaderTemplate>
<asp:Label ID="Label4" runat="server" Font-Bold="True"
Text=""></asp:Label>
<br />
Instructions: Select the candidate(s) of your choice by clicking the Checkbox <img src="images/check.png" alt="" /> and the the Oval <br /><img src="images/oval.png" alt="" /> adjacent to the candidate
<br /><img src="images/line.gif" alt="" />
<br />
</HeaderTemplate>
<AlternatingItemStyle BackColor="#DCDCDC" />
<FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
<FooterTemplate>
<tr vAlign="center">
<td align="center">
<asp:ImageButton ID="Button1" runat="server" alt="Submit"
ImageUrl="images/btn-submit-vote.png" OnClick="Button1_Click"
onmouseout="this.src='images/btn-submit-vote.png'"
onmouseover="this.src='images/btn-submit-vote.png'" style="text-align: center;"
title="Submit" />
</td></tr>
</FooterTemplate>
<SelectedItemStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
</asp:DataList>
<asp:Label ID="Label5" runat="server" EnableViewState="False" Font-Bold="True" ForeColor="Red"></asp:Label></td>
</tr>
</table>
</fieldset>
</asp:Panel>
<asp:label id="lblMsg" font-size="Medium" runat="server"></asp:label>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:BallotsConnectionString %>"
SelectCommand="SELECT [ElectionName_Position] = CASE WHEN GROUPING(mh.PositionId) = 0 THEN MAX(mh.Position) ELSE mh.ElectionName END
,CandidateName = CASE WHEN GROUPING(mh.PositionId) = 0 THEN MAX(mh.CandidateName) ELSE '' END
,PositionId = CASE WHEN GROUPING(mh.PositionId) = 0 THEN mh.PositionId ELSE 0 END
,AnswerType = CASE WHEN GROUPING(mh.PositionId) = 0 THEN MAX(mh.AnswerType) ELSE '' END
FROM PreAgg mh
GROUP BY ElectionName,PositionId WITH ROLLUP
HAVING GROUPING(mh.ElectionName) = 0
ORDER BY mh.ElectionName, GROUPING(mh.PositionId) DESC, mh.PositionID;">
<SelectParameters>
<asp:SessionParameter SessionField="ElectionId" Type="Int32" Name="ElectionId" DefaultValue="0" />
</SelectParameters>
</asp:SqlDataSource>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</form>
</body>
</html>
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If IsPostBack Then
Dim rb1 As CheckBoxList = DataList1.FindControl("RadioButtonList1")
rb1.Items.Add("writein")
Dim tb As TextBox = New System.Web.UI.WebControls.TextBox()
Dim btnDiv = DataList1.FindControl("buttonDiv")
tb.ID = "writein"
tb.Text = " "
tb.Visible = False
btnDiv.Controls.Add(tb)
End If
Protected Sub RadioButtonList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
Dim rbl As RadioButtonList = Page.Form.FindControl("RadioButtonList1")
If rbl.SelectedItem.Text = "Write In Candidate" Then
Page.Form.FindControl("writein").Visible = True
Else
Page.Form.FindControl("writein").Visible = False
End If
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs)
Dim questld As HiddenField = DataList1.FindControl("HiddenField2")
For Each item As DataListItem In DataList1.Items
If item.ItemType = ListItemType.Item Or item.ItemType = ListItemType.AlternatingItem Then
Dim positionid As Integer
Dim choiceid As Integer = 0
Dim choicetext As String = ""
positionid = CType(item.FindControl("HiddenField2"), HiddenField).Value
Dim anstype As HiddenField = item.FindControl("HiddenField1")
Select Case anstype.Value
Case "S"
Dim rbl As RadioButtonList = item.FindControl("RadioButtonList1")
Dim txt1 As TextBox = item.FindControl("writein")
If rbl.SelectedValue = 33 Then
txt1.Visible = True
Else
txt1.Visible = False
End If
choiceid = rbl.SelectedValue
SaveVotes(positionid, choiceid, "", "NA")
Case "M"
Dim cbl As CheckBoxList = item.FindControl("CheckBoxList1")
For i As Integer = 0 To cbl.Items.Count - 1
If cbl.Items(i).Selected Then
choiceid = cbl.Items(i).Value
SaveVotes(positionid, choiceid, "", "NA")
End If
Next
Case "T"
Dim txt As TextBox = item.FindControl("TextBox1")
choicetext = txt.Text
SaveVotes(positionid, 0, choicetext, "")
End Select
End If
Next
DataList1.Visible = False
End Sub
When I run this code, I get following error:
Object reference not set to an instance of an object.
Line 36: rb1.Items.Add("writein")
Thanks a lot in advance for your help
|
|
|
|
|
samflex wrote: Object reference not set to an instance of an object. The object rb1 has not been initialised; use your debugger to diagnose why this happens.
|
|
|
|
|
<headerstyle backcolor="#4A3C8C" font-bold="True" forecolor="#E7E7FF">
<asp:panel id="PanelOutDCItemDetails" runat="server">
<asp:gridview id="gvOutDCItemDetails" runat="server" allowpaging="True"
="" pagesize="6" autogeneratecolumns="False" onrowdatabound="gvOutDCItemDetails_RowDataBound" onrowcommand="gvOutDCItemDetails_RowCommand" onselectedindexchanged="gvOutDCItemDetails_SelectedIndexChanged" backcolor="White" bordercolor="White" borderstyle="Ridge" borderwidth="2px" cellpadding="3" cellspacing="1" gridlines="None" datakeynames="Item_Id">
<columns>
<asp:commandfield showdeletebutton="True">
<asp:boundfield headertext="Item Id" datafield="Item_Id">
<asp:boundfield headertext="Item Name" datafield="IName">
<asp:boundfield headertext="Net Quantity" datafield="I_Quantity">
<asp:boundfield datafield="Remaining_Qty" headertext="Remaining Quantity">
<asp:templatefield headertext="Process">
<itemtemplate>
<asp:dropdownlist id="ddrProcess" runat="server">
<asp:templatefield headertext="Dispatch Quantity">
<itemtemplate>
<asp:textbox id="txtDispatchQuantity" runat="server" autopostback="true" ontextchanged="TextChanged_txtDispatchQuantity">
<asp:templatefield headertext="Remaining Quantity">
<itemtemplate>
<asp:textbox id="txtRamainingQuantity" runat="server">
<asp:templatefield headertext="Rate">
<itemtemplate>
<asp:textbox id="txtRate" runat="server" autopostback="true" ontextchanged="txtRate_TextChanged">
<asp:templatefield headertext="Amount">
<itemtemplate>
<asp:textbox id="txtAmount" runat="server">
<asp:templatefield>
<itemtemplate>
<asp:label id="lblStatus" runat="server" text="Status">
<footerstyle backcolor="#C6C3C6" forecolor="Black">
<headerstyle backcolor="#4A3C8C" font-bold="True" forecolor="#E7E7FF">
<pagerstyle backcolor="#C6C3C6" forecolor="Black" horizontalalign="Right">
<rowstyle backcolor="#DEDFDE" forecolor="Black">
<selectedrowstyle backcolor="#9471DE" font-bold="True" forecolor="White">
<sortedascendingcellstyle backcolor="#F1F1F1">
<sortedascendingheaderstyle backcolor="#594B9C">
<sorteddescendingcellstyle backcolor="#CAC9C9">
<sorteddescendingheaderstyle backcolor="#33276A">
<selectedrowstyle backcolor="#9471DE" font-bold="True" forecolor="White">
Here is my C# code
protected void gvOutDC_SelectedIndexChanged1(object sender, EventArgs e)
{
if (gvOutDC.SelectedIndex >= 0)
{
btnsave.Enabled = false;
btnInword.Visible = false;
OutDC.Visible = true;
OutDCItemDetails.Visible = true;
View.Visible = false;
InwordDetails.Visible = false;
txtOutId.Visible = true;
txtoutCode.Enabled = false;
btn.Visible = true;
txtcustcode.Enabled = false;
btnsave.Enabled = true;
txtOutId.Text = gvOutDC.SelectedDataKey[0].ToString();
txtoutCode.Text = gvOutDC.SelectedRow.Cells[2].Text.ToString();
txtDate.Text =gvOutDC.SelectedRow.Cells[8].Text.ToString();
txtCustomerId.Text = gvOutDC.SelectedRow.Cells[5].Text.ToString();
txtcustcode.Text = gvOutDC.SelectedRow.Cells[7].Text.ToString();
txtCustomerName.Text = gvOutDC.SelectedRow.Cells[6].Text.ToString();
int inworditem = Convert.ToInt16(gvOutDC.SelectedRow.Cells[3].Text.ToString());
SqlCommand cmd = new SqlCommand("sp_getOutDCmaterialDetail",con1);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@outDCid", txtOutId.Text);
cmd.Parameters.AddWithValue("@inwordItem", inworditem);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
con1.Open();
gvOutDCItemDetails.DataSource = ds;
gvOutDCItemDetails.DataBind();
OutDCItemDetails.Visible = true;
}
}
protected void gvOutDCItemDetails_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DropDownList ddList = (DropDownList)e.Row.FindControl("ddrProcess");
SqlCommand cmd = new SqlCommand("sp_getProcess", con1);
cmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
DataTable dt = ds.Tables[0];
ddList.DataSource = dt;
ddList.DataTextField = "PName";
ddList.DataValueField = "Process_Id";
ddList.DataBind();
ddList.Items.Insert(0,new ListItem("--SELECT--","0"));
TextBox txtDispatchQuantity = (TextBox)e.Row.FindControl("txtDispatchQuantity");
txtDispatchQuantity.Text = ds.Tables[0].Rows[0][3].ToString();
TextBox txtRamainingQuantity = (TextBox)e.Row.FindControl("txtRamainingQuantity");
txtRamainingQuantity.Text = ds.Tables[0].Rows[0][3].ToString();
TextBox txtRate = (TextBox)e.Row.FindControl("txtRate");
txtRate.Text = ds.Tables[0].Rows[0][3].ToString();
TextBox txtAmount = (TextBox)e.Row.FindControl("txtAmount");
txtAmount.Text = ds.Tables[0].Rows[0][3].ToString();
}
if (e.Row.RowType == DataControlRowType.Footer)
{
}
}
for update record in my OutWordChallan Page
On selectedindexchaged i want to set vaues of textbox in item template of gridview ...
using dataset ...
but how can i assign vaues when we actually dont know how many rows in my dataset
please help me thr this
really thankfull
|
|
|
|
|
hi to all
i have a crystal report in asp.net.
and i want to test this report with send uper 100 request to this report.
how can i do this.
i think we can do this with multi threading but i dont know that how do this!!
thanks for any help
|
|
|
|
|
`You can create a unit test[^]
Alternatively You can create a new project that has a very basic GUI and calls whatever you need to call.
Create a for loop and in each loop you can start a new thread[^] calling the method that will create a report.
Also read up on load testing[^]
hope this helps.
|
|
|
|
|
Show me sample code to bind data to option value in Classic ASP.
Now, I use manual method to add items in select-option.
<title>
Boook ID
Book Name
Author Name
Ye Htut
Thaw Tar Swe
Shwe U Daung
Tar Yar Min Wai
<%
Dim conn
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "Provider=SQLOLEDB; Data Source = (local); Initial Catalog = Test; User Id = sa; Password=as"
Dim MyRs 'As ADODB.Recordset
Set MyRs = Server.CreateObject("ADODB.Recordset")
MyRs.CursorLocation = 3 'adUseClient
Dim Id, name,sql
Id = request.QueryString("id")
name = request.QueryString("name")
authorname = request.QueryString("author")
if name<>"" Then
sql="Insert into book(bid,bname,aid) VALUES ('"& Id &"','" & name &"', ' " & authorname & "')"
conn.Execute(sql)
conn.close
set sql = Nothing
else
response.write("Enter Name")
End if
%>
Thz
|
|
|
|
|
|
Hi, have following situation:
Using a dropdownlist with sqldatasource as source for selectedvalue and objectdatasource as source for the listitems.
I have added 1 item to the dropdownlist in the aspx page. It doesn't show up on the page though. I'm guessing the databind clears the listitems, but where is the best place to put it then?
If I get a null value from the sqldatasource, I need to select the manually added item. If not, I need to select an item from the databound listitems. Of course, if the manually added item stays selected, I need to return that null value back to the sqldatasource for insert/update. Guessing that last part needs to be done in the inserting/updating eventhandler of the sqldatasource, but otherwise, I'm not really sure what to do.
Using the customized dropdownlist I got from the Microsoft website(Customized Dropdownlist), I have fixed the problem that an exception was thrown every time I tried to select the manually inserted item, but it doesn't show on the page.
Anyone care to help me out here?
Thanks.
|
|
|
|
|
Mixing Data binding and custom elements in a Dropdown is always an headache. If the Data source is a DataTable, you can add your manual entry into the table as a row before the data binding process. Add it as the first item and you can write custom logic to handle this special case based on the index of the item selected.
|
|
|
|
|
Figured out the problem: I had disabled the inserted item. Anyone know though if you can enforce the user to select a different item other than disabling it?
|
|
|
|
|
I have a chart control in my ASPX page. At the top of the page there are some dropdown boxes to select some parameters to draw chart control and a button. Initially the chart control is invisible. After the btton click the chart control databinding will be done and visible property is set true. How to make the Chart control to be focused where it is at the down of the page after button click. Where now after postback the user has to scroll down to view the chart.
|
|
|
|
|
|
These links show when we have a hyperlink.. but i have to do it when postback i.e inside a button click event handler..
|
|
|
|
|
|
If I remember correctly,
the button click event fires a postback to the server, the page is sent to the server
background processing occurs on the server, here you can toggle the visible property
the page is sent back to the client, and then the page loads again with new HTML
the page.load event fires again
so the focus should probably be in the page.load event,
if page.ispostback {
if yyy.visible = true {
xxx.focus
}
}
try that out.
|
|
|
|
|
After working with C# for a few years now, i'm thinking about to switch my web development branch to .NET as well. But old habits die hard, and i find it very hard to do the switch. Especially considering the PHP codebase i leave behind.
So the question is, is there any good material, tips, guides, tutorials and so on, for an old PHP egghead like me?
|
|
|
|
|
At today's rapid pace of technological advancement, it is necessary to be versatile. Learning new technology does not have to be at the expense of abandoning an existing one as long as it is still relevant. Take it as an add-on, and the knowledge and experience that you have acquired for PHP should give an advantage as you would have understand how the web work and you would already have the competency in solving problem using code. It is only a matter of learning a new language and a new paradigm of coding, but one thing never change, that is your ability to solve problems using code (as you already have), albeit a different one.
To get started, try this: Learn About ASP.NET Web Forms[^]
|
|
|
|
|
I don't think i will abandon PHP anytime soon, but i will slowly, but surely shift over to ASP.NET. That's why i want to start as soon as possible to learn all the stuff that is required to produce a working web application, with the same quality standards i have for my PHP based applications.
|
|
|
|
|
|
Thanks
But Phalanger looks like the dirty way into ASP.NET!?
|
|
|
|
|
That's why mentioned as "Offtopic" there. Some people don't want to move quickly to new things so suggested that one.
BTW I forgot to mention one more useful link.
Beginner's Walk - Web Development[^]
|
|
|
|
|
That is exactly what i was looking for. Thank
|
|
|
|
|
I made the switch 7 years ago. Last year I took up PHP again, took a week to get use to it again, learn the new rules and terms. Actually my knowledge of ASP.Net made me a better PHP programer, at least I think.
With asp.net, you have to declare primitive values for everything, actually you have to declare everything, it's not like PHP where it sort of just assumes. And always check that the value exist first, or else you'll throw an exception.
Just remember that and coding should be sort of similar.
Most of the principles are the same, Just worded different. Just keep Google handy to search for comparisons. That what I did for going back to PHP.
I took up PHP again because there are so many little cash jobs out there for it in my area, and the jobs are so easy to do and take little time to complete.
|
|
|
|
|
first I made "connection.asp"
the codes in "connection.asp" file are as follows
<%
Dim conn
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "Provider=SQLOLEDB; Data Source = (local); Initial Catalog = Test; User Id = sa; Password=as"
If conn.errors.count = 0 Then
Response.Write "Connected OK"
End If
%>
then I made "author.asp". The following code are in "author.asp"
<title>
AuthorID
Author Name
<%
dim aid,aname,objs
aid=Request.form("aid")
aname=Request.form("aname")
Set objdb=conn()
query = "INSERT INTO author (aid,aname) VALUES ('"& aid &"','"& aname &"')"
Set objs = objdb.Execute(query)
Response.Redirect ("thankyou.asp")
%>
the code can't run. I think, there may be error in "author.asp". So, Plz help me
|
|
|
|