Pass DataBinder value in ASP.NET Repeater to database through submit button - repeater

How I can pass this value :<%#DataBinder.Eval(Container, "DataItem.QuestionsText")%> , TO THE SUBMIT CODE : database.InsertUpdate(String.Format("CALL spSurveyAnswer_Insert('{0}', '{1}','{2}');", selectValue1, txtFeedBack.Text, IneedToPassitHere )) ,
by the way , the dataBinder exist in the below code :
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1">
<HeaderTemplate>
<table class="tblcolor">
<tr class="rowcolor">
<b>
</b>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr class="tblrowcolors">
<td> <%#DataBinder.Eval(Container, "DataItem.QuestionsText")%></td>
<asp:RadioButtonList ID="RadioButtonList1" runat="server" RepeatDirection="Horizontal">
<asp:ListItem Text="1" selected="true" Value="Item1"/>
<asp:ListItem Text="2" Value="Item2"/>
<asp:ListItem Text="3" Value="Item3"/>
<asp:ListItem Text="4" Value="Item4"/>
<asp:ListItem Text="5" Value="Item5"/>
</asp:RadioButtonList>
Thanks in Advance ...

I have solve this problem by adding label to hold the value such as:
<asp:Label ID="Label1" runat="server" Text='<%# Eval("Survey_Questions_ID")%>' Visible="false"></asp:Label>
and then call this label in the repeater function such as:
Label lbl = (Label)item.FindControl("Label1");
Response.Write(lbl.Text);
Cheers

Related

extract content from html snippet

I have the following code snippet and I'm looking for a better way to parse out the last name.
<TABLE BORDER="0" class="info" width="560">
<TR>
<TD VALIGN="top"> <B>First Name<B></FONT> </TD>
<TD VALIGN="top"> <INPUT TYPE="text" NAME="First_Name" SIZE="16" value="Ashley"> </TD>
<TD VALIGN="top"> <B>Last Name<B></FONT> </TD>
<TD VALIGN="top"> <INPUT TYPE="text" NAME="Last_Name" SIZE="16" value="Smith"> </TD>
</TR>
<tr>
<TD VALIGN="top" colspan="2"> <B>Company Name (if any):<B></FONT> </TD>
<TD VALIGN="top" colspan="2"> <INPUT TYPE="text" NAME="Company_Name" SIZE="24" value=""> </TD>
</tr>
<TR>
<TD VALIGN="top" colspan=2> <B>Address<B></FONT> </TD>
<TD VALIGN="top" colspan=2> <INPUT TYPE="text" NAME="Address" SIZE="24" value="123 Any Street Circle "> </TD>
</TR>
<tr>
<TD VALIGN="top" colspan=2> <B>City <B></FONT> <INPUT type="text" id="City" name="City" SIZE="14" value="Shady Town"> </TD>
<TD colspan="2" VALIGN="top"> <B>State<B></FONT> <INPUT type="text" id=State name=State SIZE="4" value="Tx"> <B>Zip<B></FONT> <INPUT type="text" id=Zip name=Zip SIZE="8
I have the following but I'm pretty sure I can do this without having to do the replace. What I'm trying to do below is find the starting point, finding the end point, and then taking the text in between. Then once I have that, remove the "matched" text leaving me with the value of the input field.
<cfset LastName_start = findNoCase('<INPUT TYPE="text" NAME="Last_Name" SIZE="16" value="', theString, 0)>
#lastName_start#
<cfset LastName_end = findNoCase('">', theString, 0)> #lastName_end#
<cfset lastNameValue = '#Mid(theString,LastName_start,LastName_end)#'>
#lastNameValue#
<cfset lastNameValue = replace(lastNameValue, '<INPUT TYPE="text" NAME="Last_Name" SIZE="16" value="', '')>
<cfset lastNameValue = replace(lastNameValue, '">', '')>
<cfset lastNameValue = listFirst(lastNameValue,'"')>
<cfdump var="#lastNameValue#" label="lastNameValue">
Any tips on how I can clean this up using ColdFusion? This is an ethical exercise.
And yes, I did try to format this.
I second Scott Stroz's suggestion about trying JSoup. It usually works well, and is very simple to use.
Download the JSoup jar and load it in your Application.cfc.
component {
this.name = "MyApplication";
this.javaSettings = { loadPaths = ["C:\path\to\jsoup-1.12.1.jar"] };
// ... more application settings
}
Create an instance of JSoup, parse the HTML string and use val() to grab the text of the first matching element. It returns an empty string if the element wasn't found.
You can find a bunch of other helpful examples in the JSoup Cookbook.
<cfscript>
yourHTMLString = '<TABLE BORDER="0" class="info" ......';
// parse html
jsoup = createObject("java", "org.jsoup.Jsoup");
root = jsoup.parse( yourHTMLString );
// get the first matching value ...
lastName = root.select("input[name='Last_Name']").val();
firstName = root.select("input[name='First_Name']").val();
companyName = root.select("input[name='Company_Name']").val();
cityName = root.select("input[name='City']").val();
stateName = root.select("input[name='State']").val();
address = root.select("input[name='Address']").val();
</cfscript>
Results:

Thymeleaf , Map object which has value as List of districts .?

Suppose we have a Map object which has State as it's Key and List of districts in a State as it's Value. This how I am iterating over this kind of Map object.but each district is NOT getting printed on a new row. Can someone help ???
<div th:if="${not #lists.isEmpty(stateToDistrictMap)}">
<table>
<tr><td>State</td><td>Districts</td></tr>
<th:block th:each="state : ${stateToDistrictMap}">
<tr>
<td th:text="${state.key}">State</td>
<th:block th:each="district : ${state.value}">
<td th:text="${district.name}">District</td>
<td th:text="${district.code}">District</td>
<td th:text="${district.erstyear}">District</td>
<td th:text="${district.info}">District</td>
</th:block>
</tr>
</th:block>
</table>
</div>
Can someone help ???
You probably want something like:
<div th:if="${not #lists.isEmpty(stateToDistrictMap)}">
<table>
<tr>
<td>State</td>
<td>Districts</td>
</tr>
<th:block th:each="state: ${stateToDistrictMap}">
<tr th:each="district, i: ${state.value}">
<td th:text="${i.first ? state.key : ' '}" />
<td th:text="${district.name}" />
<td th:text="${district.code}" />
<td th:text="${district.erstyear}" />
<td th:text="${district.info}" />
</tr>
</th:block>
</table>
</div>

BeautifulSoup extract data from certain columns from a table I am getting too much data out

I am trying to extract some data out of my Selenium Test Report html file.
I am getting too much data out of the table of rows and columns.
The data I would like to extract is all columns which have the class value "testcase" and there is a column below with a class value "popup_link" and the text value will say Pass or Fail.
E.g.
<td class='none'><div class='testcase'>test_000001_login_valid_user</div></td>
<a class="popup_link" onfocus='this.blur();' href="javascript:showTestDetail('div_pt1.1')" >
pass</a>
I would like the text "test_000001_login_valid_user" and the text "pass"
There are lots of test cases in my report so I would like to iterate over the rows and get the test case name out and the pass or fail text.
My HTML snippet is:
<table id='result_table'>
<colgroup>
<col align='left' />
<col align='right' />
<col align='right' />
<col align='right' />
<col align='right' />
<col align='right' />
</colgroup>
<tr id='header_row'>
<td>Test Group/Test case</td>
<td>Count</td>
<td>Pass</td>
<td>Fail</td>
<td>Error</td>
<td>View</td>
</tr>
<tr class='passClass'>
<td>Regression_TestCase.RegressionProjectEdit_TestCase.RegressionProject_TestCase_Project_Edit</td>
<td>75</td>
<td>75</td>
<td>0</td>
<td>0</td>
<td>Detail</td>
</tr>
<tr id='pt1.1' class='hiddenRow'>
<td class='none'><div class='testcase'>test_000001_login_valid_user</div></td>
<td colspan='5' align='center'>
<!--css div popup start-->
<a class="popup_link" onfocus='this.blur();' href="javascript:showTestDetail('div_pt1.1')" >
pass</a>
<div id='div_pt1.1' class="popup_window">
<div style='text-align: right; color:red;cursor:pointer'>
<a onfocus='this.blur();' onclick="document.getElementById('div_pt1.1').style.display = 'none' " >
[x]</a>
</div>
<pre>
pt1.1: *** test_login_valid_user ***
test login with a valid user - Passed
</pre>
</div>
<!--css div popup end-->
</td>
</tr>
<tr id='pt1.2' class='hiddenRow'>
<td class='none'><div class='testcase'>test_000002_select_a_project</div></td>
<td colspan='5' align='center'>
<!--css div popup start-->
<a class="popup_link" onfocus='this.blur();' href="javascript:showTestDetail('div_pt1.2')" >
pass</a>
<div id='div_pt1.2' class="popup_window">
<div style='text-align: right; color:red;cursor:pointer'>
<a onfocus='this.blur();' onclick="document.getElementById('div_pt1.2').style.display = 'none' " >
[x]</a>
</div>
<pre>
pt1.2: *** test_login_valid_user ***
test login with a valid user - Passed
*** test_select_a_project ***
08_12_1612_08_03
Selenium_Regression_Edit_Project_Test
</pre>
</div>
<!--css div popup end-->
</td>
</tr>
<tr id='pt1.3' class='hiddenRow'>
<td class='none'><div class='testcase'>test_000003_verify_Lademo_CRM_DataPreview_is_present</div></td>
<td colspan='5' align='center'>
<!--css div popup start-->
<a class="popup_link" onfocus='this.blur();' href="javascript:showTestDetail('div_pt1.3')" >
pass</a>
<div id='div_pt1.3' class="popup_window">
<div style='text-align: right; color:red;cursor:pointer'>
<a onfocus='this.blur();' onclick="document.getElementById('div_pt1.3').style.display = 'none' " >
[x]</a>
</div>
<pre>
pt1.3: *** test_login_valid_user ***
test login with a valid user - Passed
*** test_select_a_project ***
08_12_1612_08_03
Selenium_Regression_Edit_Project_Test
*** Test verify_Lademo_CRM_DataPreview_is_present ***
aSelenium_LADEMO_CRM_DONOTCHANGE
File
498
</pre>
</div>
<!--css div popup end-->
</td>
</tr>
My code is:
from bs4 import BeautifulSoup
table = soup.select_one("#result_table")
for row in table.select("tr.hiddenRow"):
print(" ".join([td.text for td in row.find_all("td")]))
How can i achieve this please?
Thanks, Riaz
Check each row for both, if both exist then extract the text:
from bs4 import BeautifulSoup
soup = BeautifulSoup(html)
for row in soup.select("#result_table tr"):
div, a = row.select_one("div.testcase"), row.select_one("a.popup_link")
if div and a:
print(div.text.strip(), a.text.strip())
which gives you:
(u'test_000001_login_valid_user', u'pass')
(u'test_000002_select_a_project', u'pass')
(u'test_000003_verify_Lademo_CRM_DataPreview_is_present', u'pass')
Of course if they always go together we can simplify to:
from bs4 import BeautifulSoup
soup = BeautifulSoup(html)
for div in soup.select("#result_table tr div.testcase"):
print(div.text.strip(), div.find_next("a", class_="popup_link").text.strip())

Find control of repeater nested in datalist on repeater item command

In my code repeater is nested in datalistdatalist contains checkboxes and radiobutton
i want to do database operation on checkchanged of checkboxes,so i had written this operation on repeater itemcomand. Here I am not able to find control of repeater.so please guide me how to find control of repeater.
My design is like this:
<asp:DataList ID="DatalistQues" runat="server" DataKeyField="QuestionID" OnSelectedIndexChanged="DataListText_SelectedIndexChanged"
Width="100%" OnItemCommand="Repeater1_ItemCommand">
<ItemTemplate>
<table width="100%">
<tr>
<td style="width: 13%">
<asp:LinkButton ID="LinkButton6" runat="server" CommandName="Select" CssClass="ppppp">
<asp:Image ID="Image1" runat="server" ImageUrl='<% #Eval("Image")%>' Height="60px"
Width="65px" />
</asp:LinkButton>
</td>
<td style="width: 87%">
<asp:LinkButton ID="LinkButton7" runat="server" CommandName="Select" CssClass="ppppp">
<asp:Label ID="Label3" runat="server" Text='<% #Eval("name")%>'></asp:Label>
</asp:LinkButton>
</td>
</tr>
<tr>
<td style="width: 13%">
</td>
<td style="width: 87%; white-space: pre-line">
<asp:Label ID="TextBox2" runat="server" Text='<% #Eval("Question")%>'></asp:Label>
</td>
</tr>
<tr>
<td style="width: 13%">
</td>
<td style="width: 87%">
<script type="text/javascript" language="javascript">
function fnCheckUnCheck(objId) {
var grd = document.getElementById("TabContainer1_TabPanel2_DatalistQues");
alert(grd);
//Collect A
var rdoArray = grd.getElementsByTagName("input");
alert(rdoArray);
for (i = 0; i <= rdoArray.length - 1; i++) {
if (rdoArray[i].type == 'radio') {
if (rdoArray[i].id != objId) {
rdoArray[i].checked = false;
}
}
}
}
</script>
<asp:Repeater ID="RepeaterQues" runat="server" OnItemCommand="Repeater1_ItemCommand">
<HeaderTemplate>
</HeaderTemplate>
<ItemTemplate>
<table style="border: none">
<tr>
<td style="width: 100px">
<asp:LinkButton ID="LinkButton23" runat="server" CommandName="radiob">
<asp:RadioButton ID="RadioButton1" runat="server" onclick="fnCheckUnCheck(this.id);" /></asp:LinkButton><asp:LinkButton
ID="LinkButton24" runat="server" CommandName="checkb">
<asp:CheckBox ID="CheckBox1" runat="server" Text='<%#Eval("QOption") %>' /></asp:LinkButton>
</td>
<td style="width: 100px">
<asp:Label ID="empname" Text='<%#Eval("QOption") %>' runat="server"></asp:Label>
</td>
</tr>
</table>
</ItemTemplate>
</asp:Repeater>
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
Try this
((Repeater)e.Item.Parent).ID // this gives the ID as specified on the aspx page
If you need Unique ID, you have to use this
((Repeater)e.Item.Parent).ClientID
On Item command of Repeater you will have to first find the naming container of sender
it will return you datalist item.
then in returned list item you will have to find the repeater of that particular data list itme
once you will find the repeater you can easily find the controls of the item of repeater

JQuery - Problem with selectors (siblings, parents...)

I got a coldfusion query where the result is grouped on country names. With a click on this one, I try to open or close the list under the country. But i cannot work correctly with this siblings and this parents. The result is, if i click on a country name, the fourth one, for example, it close all childrens, and the three country name which are before too.
Can someone help me to choose the right selectors ?
Thank you in advance ,
Michel
The code:
<script type="text/javascript" language="javascript">
$(document).ready(function(){
var toggleMinus = '<cfoutput>#variables.strWebAddress#</cfoutput>/images/bullet_toggle_minus.png';
var togglePlus = '<cfoutput>#variables.strWebAddress#</cfoutput>/images/bullet_toggle_plus.png';
var $subHead = $('table#categorylist tbody th:first-child');
$subHead.prepend('<img src="' +toggleMinus+ '" alt="collapse this section" /> ');
$('img', $subHead).addClass('clickable').click(function(){
var toggleSrc = $(this).attr('src');
if(toggleSrc == toggleMinus){
$(this).attr('src',togglePlus).parents('.country').siblings().fadeOut('fast');
}else{
$(this).attr('src',toggleMinus).parents('.country').siblings().fadeIn('fast');
}
});
});
</script>
<table width="95%" border="0" cellspacing="2" cellpadding="2" align="center id="categorylist">
<thead>
<tr>
<th class="text3" width="15%">
<cfmodule template="../custom_tags/get_message.cfm" keyName="L_ACTOR_CODENUMBER">
</th>
<th class="text3" width="15%">
<cfmodule template="../custom_tags/get_message.cfm" keyName="L_ACTOR_CODE">
</th>
<th class="text3" width="55%">
<cfmodule template="../custom_tags/get_message.cfm" keyName="L_ACTOR_NAME">
</th>
<th class="text3" width="15%">
<cfmodule template="../custom_tags/get_message.cfm" keyName="L_ACTIVE">
</th>
</tr>
</thead>
<tbody id="content">
<cfoutput query="qryCategoryUrl" group="country_name" groupcasesensitive="false">
<tr class="country">
<th style="font-weight:bold; text-align:left;" colspan="4">#country_name#</th>
</tr>
<cfoutput>
<tr>
<td valign="top" class="text3">#Replace(ACTOR_CODENUMBER, Chr(13) & Chr(10), "<br>", "ALL")# </td>
<td valign="top" class="text3">#Replace(ACTOR_CODE, Chr(13) & Chr(10), "<br>", "ALL")# </td>
<td valign="top" class="text3">#Replace(ACTOR_NAME, Chr(13) & Chr(10), "<br>", "ALL")# </td>
<td valign="top" class="text3"><cfmodule template="../custom_tags//get_message.cfm" keyName="#ACTIVE_display(qryCategoryUrl.ACTIVE)#"></td>
</tr>
</cfoutput>
</cfoutput>
</tbody>
</table>
Instead of:
.parents('.country').siblings().fadeOut('fast');
Try this:
.closest('.country').nextUntil('.country').fadeOut('fast');
And of course, apply the same change to the .fadeIn(). You might also look into .fadeToggle()docs.
Here's a (reduced) example: http://jsfiddle.net/redler/5sqJz/. While it doesn't affect the example, presumably you would be setting the initial state of those detail rows as hidden.
woah all that cfmodule usage, cfmodule can be a memory hog.
Although what I always recommend is that people try their pages in whatever browser, and use the SelectorGadget bookmarklet at http://www.selectorgadget.com/
This makes it easier to test and check the correct selector, for your app needs.