First Excuse my English is bad!!!
I have A Web Form Where there are 120 RadioButtonList .I should monitored them
if (RadioButtonList1.SelectedValue == "1")
{
Response.Write("1");
}
else
{
Response.Write("0");
}
if (RadioButtonList2.SelectedValue == "1")
{
Response.Write("1");
}
else
{
Response.Write("0");
}
if (RadioButtonList3.SelectedValue == "1")
{
Response.Write("1");
}
else
{
Response.Write("0");
}
.
.
.
if (RadioButtonList120.SelectedValue == "1")
{
Response.Write("1");
}
else
{
Response.Write("0");
}
now i want do this whit For loop
Like this:
for (int i = 1; i <= 120; i++)
{
if (RadioButtonList[i].SelectedValue == "1")//Like Array :))
{
Response.Write("1");
}
else
{
Response.Write("0");
}
}
(This example is stupid.)
How did it do ?
again Excuse my English is bad!!!
string id="radiobuttonlist";
for(int i=1;i<121;i++)
{
id=id+i.ToString();
RadioButtonList rbl = (RadioButtonList)Page.FindControl(id);
if(rbl.SelectedValue == 1)
{
//do something
}
else
{
//do something
}
}
Related
When see the qt source code(QEventDispatcherWin32::processEvents),i find a Logical issues.code as below,first it writes if(!haveMessage) next if(haveMessage),so code else if (...) and else{...} will never execute,what i think is right?
code as:
if (!haveMessage) {
// no message - check for signalled objects
for (int i = 0; i < (int)nCount; i++)
pHandles[i] = d->winEventNotifierList.at(i)->handle();
waitRet = MsgWaitForMultipleObjectsEx(nCount, pHandles, 0, QS_ALLINPUT, MWMO_ALERTABLE);
if ((haveMessage = (waitRet == WAIT_OBJECT_0 + nCount))) {
// a new message has arrived, process it
continue;
}
}
if (haveMessage) {
#ifdef Q_OS_WINCE
// WinCE doesn't support hooks at all, so we have to call this by hand :(
(void) qt_GetMessageHook(0, PM_REMOVE, (LPARAM)&msg);
#endif
if (d->internalHwnd == msg.hwnd && msg.message == WM_QT_SENDPOSTEDEVENTS) {
if (seenWM_QT_SENDPOSTEDEVENTS) {
// when calling processEvents() "manually", we only want to send posted
// events once
needWM_QT_SENDPOSTEDEVENTS = true;
continue;
}
seenWM_QT_SENDPOSTEDEVENTS = true;
}
else if (msg.message == WM_TIMER) {
// avoid live-lock by keeping track of the timers we've already sent
bool found = false;
for (int i = 0; !found && i < processedTimers.count(); ++i) {
const MSG processed = processedTimers.constData()[i];
found = (processed.wParam == msg.wParam && processed.hwnd == msg.hwnd && processed.lParam == msg.lParam);
}
if (found)
continue;
processedTimers.append(msg);
}
else if (msg.message == WM_QUIT) {
if (QCoreApplication::instance())
QCoreApplication::instance()->quit();
return false;
}
if (!filterEvent(&msg)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
else if (waitRet >= WAIT_OBJECT_0 && waitRet < WAIT_OBJECT_0 + nCount) {
d->activateEventNotifier(d->winEventNotifierList.at(waitRet - WAIT_OBJECT_0));
}
else {
// nothing todo so break
break;
}
now i encountered a very very weird issue. below is the code. pardon the length. This class has multiple function that were working when there only 3 (upt to button C)buttons being reference, in fact the one installed on my phone has the already pressed button disabled after i go back to the initial scene.
So me thinking all is good decided to do this for all the buttons that I have on my initial Screen. But for some reason it is not working, it is not disabling the buttons anymore. I have the GameLogic.cs where i have my variables declared and this script as well. 16 buttons = 16 Alphabets. So basically it just increments a value once button is pressed then once we go back to the initial screen On update, if the value is >= 1 then that particular button must be disabled.
Again it is working when i first built it for the phone. it is there. this is so weird. Maybe you can see some issue with the code here perhaps?
Thanks.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class forButtonDisabler : MonoBehaviour {
public Button buttonA;
public Button buttonB;
public Button buttonC;
public Button buttonD;
public Button buttonE;
public Button buttonF;
public Button buttonG;
public Button buttonH;
public Button buttonI;
public Button buttonJ;
public Button buttonK;
public Button buttonL;
public Button buttonM;
public Button buttonN;
public Button buttonO;
public Button buttonP;
void OnEnable()
{
//Register Button Events
buttonA = GameObject.Find("btn5ptsPP").GetComponent<Button>();
buttonB = GameObject.Find("btn5ptsDP").GetComponent<Button>();
buttonC = GameObject.Find("btn5ptsTE").GetComponent<Button>();
buttonD = GameObject.Find("btn5ptsTA").GetComponent<Button>();
buttonE= GameObject.Find("btn10ptsPP").GetComponent<Button>();
buttonF = GameObject.Find("btn10ptsDP").GetComponent<Button>();
buttonG = GameObject.Find("btn10ptsTE").GetComponent<Button>();
buttonH = GameObject.Find("btn10ptsTA").GetComponent<Button>();
buttonI = GameObject.Find("btn15ptsPP").GetComponent<Button>();
buttonJ = GameObject.Find("btn15ptsDP").GetComponent<Button>();
buttonK = GameObject.Find("btn15ptsTE").GetComponent<Button>();
buttonL = GameObject.Find("btn15ptsTA").GetComponent<Button>();
buttonM = GameObject.Find("btn20ptsPP").GetComponent<Button>();
buttonN = GameObject.Find("btn20ptsDP").GetComponent<Button>();
buttonO = GameObject.Find("btn20ptsTE").GetComponent<Button>();
buttonP = GameObject.Find("btn20ptsTA").GetComponent<Button>();
buttonA.onClick.AddListener(() => buttonCallBack(buttonA));
buttonB.onClick.AddListener(() => buttonCallBack(buttonB));
buttonC.onClick.AddListener(() => buttonCallBack(buttonC));
buttonD.onClick.AddListener(() => buttonCallBack(buttonD));
buttonE.onClick.AddListener(() => buttonCallBack(buttonE));
buttonF.onClick.AddListener(() => buttonCallBack(buttonF));
buttonG.onClick.AddListener(() => buttonCallBack(buttonG));
buttonH.onClick.AddListener(() => buttonCallBack(buttonH));
buttonI.onClick.AddListener(() => buttonCallBack(buttonI));
buttonJ.onClick.AddListener(() => buttonCallBack(buttonJ));
buttonK.onClick.AddListener(() => buttonCallBack(buttonK));
buttonL.onClick.AddListener(() => buttonCallBack(buttonL));
buttonM.onClick.AddListener(() => buttonCallBack(buttonM));
buttonN.onClick.AddListener(() => buttonCallBack(buttonN));
buttonO.onClick.AddListener(() => buttonCallBack(buttonO));
buttonP.onClick.AddListener(() => buttonCallBack(buttonP));
}
private void buttonCallBack(Button buttonPressed)
{
if (buttonPressed == buttonA)
{
GameLogic.Cbtn1++;
}
if (buttonPressed == buttonB)
{
GameLogic.Cbtn2++;
}
if (buttonPressed == buttonC)
{
GameLogic.Cbtn3++;
}
if (buttonPressed == buttonD)
{
GameLogic.Cbtn4++;
}
if (buttonPressed == buttonE)
{
GameLogic.Cbtn5++;
}
if (buttonPressed == buttonF)
{
GameLogic.Cbtn6++;
}
if (buttonPressed == buttonG)
{
GameLogic.Cbtn7++;
}
if (buttonPressed == buttonH)
{
GameLogic.Cbtn8++;
}
if (buttonPressed == buttonI)
{
GameLogic.Cbtn9++;
}
if (buttonPressed == buttonJ)
{
GameLogic.Cbtn10++;
}
if (buttonPressed == buttonK)
{
GameLogic.Cbtn11++;
}
if (buttonPressed == buttonL)
{
GameLogic.Cbtn12++;
}
if (buttonPressed == buttonM)
{
GameLogic.Cbtn13++;
}
if (buttonPressed == buttonN)
{
GameLogic.Cbtn14++;
}
if (buttonPressed == buttonO)
{
GameLogic.Cbtn15++;
}
if (buttonPressed == buttonP)
{
GameLogic.Cbtn16++;
}
}
void OnDisable()
{
//Un-Register Button Events
buttonA.onClick.RemoveAllListeners();
buttonB.onClick.RemoveAllListeners();
buttonC.onClick.RemoveAllListeners();
buttonD.onClick.RemoveAllListeners();
buttonE.onClick.RemoveAllListeners();
buttonF.onClick.RemoveAllListeners();
buttonG.onClick.RemoveAllListeners();
buttonH.onClick.RemoveAllListeners();
buttonI.onClick.RemoveAllListeners();
buttonJ.onClick.RemoveAllListeners();
buttonK.onClick.RemoveAllListeners();
buttonL.onClick.RemoveAllListeners();
buttonM.onClick.RemoveAllListeners();
buttonN.onClick.RemoveAllListeners();
buttonO.onClick.RemoveAllListeners();
buttonP.onClick.RemoveAllListeners();
}
// Update is called once per frame
void Update()
{
if (GameLogic.Cbtn1 >= 1)
{
buttonA.interactable = false;
}
if (GameLogic.Cbtn2 >= 1)
{
buttonB.interactable = false;
}
if (GameLogic.Cbtn3 >= 1)
{
buttonC.interactable = false;
}
if (GameLogic.Cbtn4 >= 1)
{
buttonD.interactable = false;
}
if (GameLogic.Cbtn5 >= 1)
{
buttonE.interactable = false;
}
if (GameLogic.Cbtn6 >= 1)
{
buttonF.interactable = false;
}
if (GameLogic.Cbtn7 >= 1)
{
buttonG.interactable = false;
}
if (GameLogic.Cbtn8 >= 1)
{
buttonH.interactable = false;
}
if (GameLogic.Cbtn9 >= 1)
{
buttonI.interactable = false;
}
if (GameLogic.Cbtn10 >= 1)
{
buttonJ.interactable = false;
}
if (GameLogic.Cbtn11 >= 1)
{
buttonK.interactable = false;
}
if (GameLogic.Cbtn12 >= 1)
{
buttonL.interactable = false;
}
if (GameLogic.Cbtn13 >= 1)
{
buttonM.interactable = false;
}
if (GameLogic.Cbtn14 >= 1)
{
buttonN.interactable = false;
}
if (GameLogic.Cbtn15 >= 1)
{
buttonO.interactable = false;
}
if (GameLogic.Cbtn16 >= 1)
{
buttonP.interactable = false;
}
}
}
What characters does Server.HtmlEncode encode into named character entities?
So far I have only found < > & and " surely there must be more than this?
This is the code of HtmlEncode, so here you can see how they done it.
public static unsafe void HtmlEncode(string value, TextWriter output)
{
if (value != null)
{
if (output == null)
{
throw new ArgumentNullException("output");
}
int num = IndexOfHtmlEncodingChars(value, 0);
if (num == -1)
{
output.Write(value);
}
else
{
int num2 = value.Length - num;
fixed (char* str = ((char*) value))
{
char* chPtr = str;
char* chPtr2 = chPtr;
while (num-- > 0)
{
chPtr2++;
output.Write(chPtr2[0]);
}
while (num2-- > 0)
{
chPtr2++;
char ch = chPtr2[0];
if (ch <= '>')
{
switch (ch)
{
case '&':
{
output.Write("&");
continue;
}
case '\'':
{
output.Write("'");
continue;
}
case '"':
{
output.Write(""");
continue;
}
case '<':
{
output.Write("<");
continue;
}
case '>':
{
output.Write(">");
continue;
}
}
output.Write(ch);
continue;
}
if ((ch >= '\x00a0') && (ch < 'Ā'))
{
output.Write("&#");
output.Write(ch.ToString(NumberFormatInfo.InvariantInfo));
output.Write(';');
}
else
{
output.Write(ch);
}
}
}
}
}
}
.NET 4 and 4.5 encode single quotes also, which doesn't appear to be in the answer
I trying to improve a textbox that filters a gridview, by implementing an enhanced textbox that can identify AND, OR, NOT operators by searching for this keywords in the string the user inputs in the textbox.
I am trying to do a regular expression to group the results but I'm not very good at this and I am failing to get what I want.
An example of what I want is as follows:
string = "build1 and build2 and build3 or build4 or not build5 and not build6"
results in a split mode:
build1 and
build2 and
build3 or
build4 or not
build5 and not
build6
This is because then I will take the first for example and replace with
SomeTable.Name_Of_Build = 'build1' AND
SomeTable.Name_Of_Build = 'build2' AND .... so on
This works for me
\w+(\sand\snot|\sor\snot|\sand|\sor|$)
I might recommend that instead of using a regular expression to group the results you do something like this. I think it would be more robust than trying to guess at the right regex.
string filter = "build1 and buil2 and build3 or build4 or not build5"
list<string> filterTokens = filter.Split(new char[] {' '})
string gridViewFilter = "";
bool notEqual = false;
foreach(string token in filterTokens)
{
if(token == "and")
{
gridViewFilter += "and"
}
else if(token == "or")
{
gridViewFilter += "or"
}
else if(token == "not")
{
notEqual = true;
}
else if(notEqual)
{
gridViewFilter += "SomeTable.Name_Of_Build <> '" + token + "'";
notEqual = false;
}
else
{
gridViewFilter += "SomeTable.Name_Of_Build <> '" + token + "'";
}
}
Also, if you really want to implement a robust and full featured sort you need to look into using Reverse Polish Notation (RPN). It would allow you to handle parentheses and order of operations. An RPN implementation would look something like this.
private bool CheckForFilterMatch(string filter, List<string> values, bool exactMatch)
{
for (int i = 0; i < values.Count; i++)
{
values[i] = values[i].ToLower();
}
if (filter.Trim() == "")
{
return true;
}
List<string> rpn = GetPostFixNotation(filter);
Stack<bool> output = new Stack<bool>();
foreach (string token in rpn)
{
if (IsValue(token))
{
bool isMatch;
if (exactMatch)
{
isMatch = values.Contains(token.ToLower());
}
else
{
isMatch = false;
foreach (string value in values)
{
isMatch = (value.IndexOf(token.ToLower()) != -1);
if (isMatch) break;
}
}
output.Push(isMatch);
}
else if (IsOperator(token))
{
bool operand1 = output.Pop();
bool operand2 = output.Pop();
if (token == "&")
{
output.Push(operand1 && operand2);
}
if (token == "|")
{
output.Push(operand1 || operand2);
}
}
}
return output.Pop();
}
public List<string> GetPostFixNotation(string filter)
{
if (filter == "")
{
return new List<string>();
}
List<string> postFixNotation = new List<string>();
Queue<string> output = new Queue<string>();
Stack<string> operators = new Stack<string>();
List<string> parsedFilter = ParseFilterTokens(filter);
foreach (string token in parsedFilter)
{
if (IsValue(token))
{
output.Enqueue(token);
}
else if (IsOperatorNoParenth(token))
{
while (operators.Count > 0 && IsOperatorNoParenth(operators.Peek()))
{
if ((operators.Count > 0 && (Precedence(token) <= Precedence(operators.Peek()))))
{
string operatorToReturn = operators.Pop();
output.Enqueue(operatorToReturn);
}
else break;
}
operators.Push(token);
}
else if (token == "(")
{
operators.Push(token);
}
else if (token == ")")
{
while (operators.Count > 0 && operators.Peek() != "(")
{
output.Enqueue(operators.Pop());
}
operators.Pop();
}
}
while (operators.Count > 0)
{
output.Enqueue(operators.Pop());
}
while (output.Count > 0)
{
postFixNotation.Add(output.Dequeue());
}
return postFixNotation;
}
Try this regex out:
(build[^b]+)
if We apply any custom decorator on radio button then it will be display on next line so how
we create such custom decorator that will display inline also same for file
checked=false;
function checkedAll (frm1) {
var aa= document.getElementById('frm1');
if (checked == false)
{
checked = true
}
else
{
checked = false
}
for (var i =0; i < aa.elements.length; i++)
{
aa.elements[i].checked = checked;
}
}
function check()
{
var aa= document.getElementById('frm1');
var flag;
for(var i =0; i < aa.elements.length; i++)
{
if(aa.elements[i].type=='checkbox')
{
if(aa.elements[i].checked && aa.elements[i].id !='checkall')
{
flag = true;
}
else if(!aa.elements[i].checked && aa.elements[i].id !='checkall')
{
flag = false;
break;
}
}
}
if(flag)
{
aa.elements.checkall.checked = true;
}
else
{
aa.elements.checkall.checked = false;
}
}
function notempty()
{
var flag=false;
var all ='';
var aa= document.getElementById('frm1');
for(var i =0; i < aa.elements.length; i++)
{
if(aa.elements[i].type=='checkbox')
{
if(aa.elements.checkall.checked)
{
flag = true;
all = 'd';
break;
}
else
{//alert(aa.elements[i].id);
if(aa.elements[i].checked && aa.elements[i].id !='checkall')
{
flag = true;
all += aa.elements[i].id.replace('check','') + '~';
}
}
}
}
if(!flag)
{
alert("please select a contact to delete..");
return false;
}
if(flag)
{
//alert(all);
document.location.href= '/member/public/index/delete?all='+all;
return false;
}
}
onclick='checkedAll(frm1);'>
escape($data->id);?>"
onclick="check();">
10px;" onclick="return notempty();" value="DELETE" />