for(i=1;i<=10;i++)
{
RadioButtonList rad = new RadioButtonList();
rad.ID = "rad" + i.ToString();
lbl.Attributes.Add("runat", "Server");
rad.Style.Add(HtmlTextWriterStyle.Position, "absolute");
rad.Style[HtmlTextWriterStyle.Top] = top + 20 + "px";
rad.Style[HtmlTextWriterStyle.Left] = "200px";
rad.Attributes.Add("runat", "Server");
}
For example, I'm creating 10 RadioButtonLists by using code, named rad1 to rad10
I wan get rad(1) to rad(10).selectedItems from users...
rad(i).selectItems gives me an error. I want to get the selected item from rad1 to rad10. Example:
answer1 = rad1.selectItems.tostring();
answer2 = rad2.selectItems.tostring();
answer3 = rad3.selectItems.tostring();
answer4 = rad4.selectItems.tostring();
answer5 = rad5.selectItems.tostring();
answer6 = rad6.selectItems.tostring();
answer7 = rad7.selectItems.tostring();
answer8 = rad8.selectItems.tostring();
answer9 = rad9.selectItems.tostring();
answer10 = rad10.selectItems.tostring();
But I can't even specify rad1.selecteditems, it's giving me an error. it keep saying that rad(i) is not exist in the context
RadioButtonList rad = new RadioButtonList();
You are naming all of your RadioButtonList objects with the same name;
You should create an array or List of RadioButtonLists
You should use following expression to find a dynamic generated control:
RadioButtonList rbl = (RadioButtonList)FindControl("rad1");
Related
I am pretty new in .NET* and **SharePoint and I have the following problem.
I am developing a Web Part (into Share Point 2013) that retrieve n SharePoint list (the number of these lists is variable, it is not a fixed number) and use the content of these lists to render n DropDown (the content of these drop down is the content of the related SharePoint list).
So basically into the Page_Load() method of my Web Part I have something like this (it works):
else if (mode != null && mode.Equals("scelta_campi_facoltativi_etichetta"))
{
SPList listaCampiOpzionaliEtichetta = contextWeb.Lists["ListaCampiOpzionaliEtichetta"];
String tipoDocumentiInternalName = listaCampiOpzionaliEtichetta.Fields["TipoDocumento"].InternalName;
Clausola c = null;
if (tipoDoc.Equals("docEntrata"))
{
c = new Clausola(Clausola.condizione.Eq, Clausola.tipoCampo.Choice, Clausola.CondizioneExtra.no, "Entrata", tipoDocumentiInternalName);
}
else if(tipoDoc.Equals("docUscita"))
{
c = new Clausola(Clausola.condizione.Eq, Clausola.tipoCampo.Choice, Clausola.CondizioneExtra.no, "Uscita", tipoDocumentiInternalName);
}
string q = Query.creaQueryWhere(c.query);
SPQuery queryQ = new SPQuery();
queryQ.Query = q;
SPListItemCollection etichetteCollection = listaCampiOpzionaliEtichetta.GetItems(queryQ);
Table table = new Table();
table.CellPadding = 2;
table.CellSpacing = 2;
table.Width = Unit.Percentage(100);
foreach (SPListItem item in etichetteCollection)
{
Debug.WriteLine("etichetta: " + item["NomeLista"] + " URL sito: " + item["UrlSito"]);
SPSite sitoEtichettaCorrente = new SPSite(item["UrlSito"].ToString()); // Top level website of the site collection
SPWeb currentWebSite = sitoEtichettaCorrente.OpenWeb();
//SPList eitchettaCorrenteList = currentWebSite.GetList(item["NomeLista"].ToString());
SPList eitchettaCorrenteList = currentWebSite.Lists[item["NomeLista"].ToString()];
String nomeColonna = item["NomeColonna"].ToString();
String codice = item["Codice"].ToString();
TableRow rigaCorrente = new TableRow();
TableCell cell1Corrente = new TableCell();
TableCell cell2Corrente = new TableCell();
cell1Corrente.Controls.Add(new LiteralControl((String)item["NomeLista"]));
DropDownList dropDownnEtichetta = new DropDownList();
for (int i = 0; i < eitchettaCorrenteList.Items.Count; i++)
{
dropDownnEtichetta.CssClass = "chosen-select";
dropDownnEtichetta.ClientIDMode = ClientIDMode.Static;
dropDownnEtichetta.ID = (String)item["NomeLista"];
string valoreDaMostrareInternalName = eitchettaCorrenteList.Fields[nomeColonna].InternalName;
string valoreDaStampareInternalName = eitchettaCorrenteList.Fields[codice].InternalName;
string valoreDaMostrare = eitchettaCorrenteList.Items[i].GetFormattedValue(valoreDaMostrareInternalName);
string valoreDaStampare = eitchettaCorrenteList.Items[i].GetFormattedValue(valoreDaStampareInternalName);
dropDownnEtichetta.Items.Add(new ListItem(valoreDaMostrare, valoreDaStampare));
cell2Corrente.Controls.Add(dropDownnEtichetta);
rigaCorrente.Controls.Add(cell1Corrente);
rigaCorrente.Controls.Add(cell2Corrente);
}
table.Controls.Add(rigaCorrente);
}
sceltaCampiEtichettaPanel.Controls.Add(table);
HtmlGenericControl buttondiv = new HtmlGenericControl("div");
Button bottoneConfermaCampiFacoltativiEtichetta = new Button();
bottoneConfermaCampiFacoltativiEtichetta.Text = "Conferma";
bottoneConfermaCampiFacoltativiEtichetta.CssClass = "shiny-blue";
//bottoneConfermaCampiFacoltativiEtichetta.OnClientClick = "return validatePwd();";
//bottoneConfermaCampiFacoltativiEtichetta.Click += ButtonSalva_Click;
buttondiv.Controls.Add(new LiteralControl("<br/>"));
buttondiv.Controls.Add(bottoneConfermaCampiFacoltativiEtichetta);
sceltaCampiEtichettaPanel.Controls.Add(buttondiv);
}
As you can see I am retrieving a list of SharePoint lists. I iterate on each list and I populate the contend of the rendered DropDown with the content of the related current list.
Now my problem is: the user can select a value from these DropDown. I want to store (probably at class level) the values chosen by the user into these dropdown.
What could be a smart strategy to implement this task?
I inherited code that uses the asp.net TreeView. There is a bug. I need to set the checkbox in the treeview from the server side. So, when the form is posted back later I can grab the values. This is what I have, I cannot find any means to set the checkbox. Any help would be appreciated
TreeNode ndGroup = new TreeNode(o.GroupName);
ndGroup.Value = o.GroupID.ToString();
ndGroup.ImageUrl = str_AdGroupImg;
ndGroup.ShowCheckBox = true;
TreeNode ndsubMember;
if (String.IsNullOrWhiteSpace(submem.Department))
{
ndsubMember = new TreeNode(submem.MemberName);
}
else
{
ndsubMember = new TreeNode(submem.MemberName + " (Dept - " + submem.Department + ")");
}
//TreeNode ndsubMember = new TreeNode(submem.MemberName);
ndsubMember.Value = submem.MemberID.ToString();
ndsubMember.ImageUrl = str_AdMeneberImg;
ndsubGroup.ChildNodes.Add(ndsubMember);
ndGroup.ChildNodes.Add(ndsubGroup);
trvEmailGroups.Nodes.Add(ndGroup);
trvEmailGroups.CollapseAll();
im working on a project(UWP C sharp) from college..
i need to build library program that manege books and magazines
i have a problem with the edit item page...
iv created method that create elements (text box, datepicker , etc..) dynamically by the type of the item that selected (if the user select book, he'll get the elements for book same for magazines..)
the problem is when im trying to write the event button that take the values from all those elements i cant reach them... cuz they in a method..
(like book.title = textbox.text;)
sorry for my English and Ty for the help:)
private void CreateBtnsByTheTypeOfTheItem(AbstractItem item)
{
TextBox editTitleTB = new TextBox();
editTitleTB.Text = LibManager.Instance.CurrentItem.Title;
Grid.SetRow(editTitleTB, 0);
editPageGrid.Children.Add(editTitleTB);
CheckBox editIsAvaibleCB = new CheckBox();
editIsAvaibleCB.Content = "Is Avaible";
editIsAvaibleCB.IsChecked = item.isAvaible;
Grid.SetRow(editIsAvaibleCB, 1);
editPageGrid.Children.Add(editIsAvaibleCB);
DatePicker editDatePicler = new DatePicker();
editDatePicler.Date = item.PublishDate;
Grid.SetRow(editDatePicler, 3);
editPageGrid.Children.Add(editDatePicler);
if (item is Book)
{
Book itemAsBook = item as Book;
TextBox editAuthor = new TextBox();
editAuthor.Text = itemAsBook.Author;
Grid.SetRow(editAuthor, 2);
editPageGrid.Children.Add(editAuthor);
var _enumval = Enum.GetValues(typeof(BookCategory)).Cast<BookCategory>();
ComboBox editCategpryCB = new ComboBox();
editCategpryCB.ItemsSource = _enumval.ToList();
editCategpryCB.SelectedItem = itemAsBook.Category;
Grid.SetRow(editCategpryCB, 4);
editPageGrid.Children.Add(editCategpryCB);
}
else
{
Magazine itemAsMagazine = item as Magazine;
TextBox editEditors = new TextBox();
editEditors.Text = itemAsMagazine.Editors;
Grid.SetRow(editEditors, 2);
editPageGrid.Children.Add(editEditors);
var _enumval = Enum.GetValues(typeof(MagazineCategory)).Cast<MagazineCategory>();
ComboBox editMagazineCategory = new ComboBox();
editMagazineCategory.ItemsSource = _enumval.ToList();
editMagazineCategory.SelectedItem = itemAsMagazine.Category;
Grid.SetRow(editMagazineCategory, 4);
editPageGrid.Children.Add(editMagazineCategory);
}
If you have named each of the dynamically created field you can access them by using the FindName method.
TextBox editTitleTB = new TextBox();
editTitleTB.Name = "TheHobbitTB";
editTitleTB.Text = LibManager.Instance.CurrentItem.Title;
TextBox theHobbitTB = (TextBox)this.FindName("TheHobbitTB");
Then you could essentially edit what ever you want about this specific textbox.
I have a form with a combobox. I'm reading a file and with info in the file I need to pre-populate this combobox.
Example:
Combobox is populated like so:
DataTable dataTable = new DataTable("Letters");
dataTable.Columns.Add("One");
dataTable.Columns.Add("Two");
dataTable.Rows.Add("AB", "Alpha Bravo");
dataTable.Rows.Add("BC", "Bravo Charlie");
dataTable.Rows.Add("CD", "Charlie Delta");
dataTable.Rows.Add("DE", "Delta Echo");
cbLetters.DataSource = dataTable;
cbLetters.DisplayMember = "Two";
cbLetters.ValueMember = "One";
cbLetters.SelectedItem = 1;
cbLetters.Refresh();
When I search like this: cbLetters.SelectedValue = FieldFromFile.ToString(); I don't retrieve any records. And the FieldFromFile is filled with "CD". I also tried cbLetters.SelectedValue = FieldFromFile.
When I search like this: cbLetters.SelectedValue = "CD"; I retrieve Charlie Delta as expected.
It's killing me. Needless to say I'm new to C#. Any help would be greatly appreciated.
Thanks a bunch!
the problem is not getting the value, the problem is the set datasource , note the ComboBox is not contains elements. Eg:
DataTable dataTable = new DataTable("Letters");
dataTable.Columns.Add("One");
dataTable.Columns.Add("Two");
dataTable.Rows.Add("AB", "Alpha Bravo");
dataTable.Rows.Add("BC", "Bravo Charlie");
dataTable.Rows.Add("CD", "Charlie Delta");
dataTable.Rows.Add("DE", "Delta Echo");
var cbLetters = new ComboBox();
cbLetters.DataSource = dataTable.DataSet;
cbLetters.DisplayMember = "Two";
cbLetters.ValueMember = "One";
cbLetters.Refresh();
var foo = cbLetters.Items.Count;
Console.Write(foo); //retun 0
Edit: The problem is your code not has any DataBind "cbLetters.DataBind();",
DataTable dataTable = new DataTable("Letters");
dataTable.Columns.Add("One");
dataTable.Columns.Add("Two");
dataTable.Rows.Add("AB", "Alpha Bravo");
dataTable.Rows.Add("BC", "Bravo Charlie");
dataTable.Rows.Add("CD", "Charlie Delta");
dataTable.Rows.Add("DE", "Delta Echo");
var cbLetters = new DropDownList();
cbLetters.DataSource = dataTable.DefaultView;
cbLetters.DataSource = new BindingSource(dataTable, null);
cbLetters.DataValueField = "one";
cbLetters.DataTextField = "two";
cbLetters.DataBind(); // Here DataBind
cbLetters.SelectedIndex = 2;
//cbLetters.Refresh();
Console.Write("value selected -> " + cbLetters.SelectedValue); //return CD
Console.Write("text selected -> " + cbLetters.SelectedItem.Text); // return Charlie Delta
Refer the Image, having 2 TextBox(tbxAttribute and tbxAttributeDesc).
Value will be loaded when page is loaded in tbxAttribute TextBox.In tbxAttributeDesc TextBox the end user will Fill that Data.
I have already Completed the Autocomplete Text in tbxAttributeDesc.
We are maintaining these Values in a table, Based up on the loaded tbxAttribute value their corresponding AttributeDesc will be highlight into tbxAttributeDesc Textbox
My Code be:
autoDesc = new AjaxControlToolkit.AutoCompleteExtender();
autoDesc.ID = "autoDesc" + i;
autoDesc.BehaviorID = "tbxAtribute" + i;
autoDesc.ServicePath = "itemvaluemas.asmx";
autoDesc.ServiceMethod = "GetAttributeDesc";
autoDesc.TargetControlID = tbxAttributeDesc.ID;
autoDesc.MinimumPrefixLength = 1;
autoDesc.CompletionInterval = 10;
autoDesc.FirstRowSelected = true;
autoDesc.CompletionSetCount = 30;
autoDesc.UseContextKey = true;
and also used Javscript Concept.
Refer the Below Image:
Here i need to pass condition as tbxAtribute and their Corresponding tbxAtributeDesc, based up on that tbxAbbr Value need to be highlight..
if i use ContextKey then how i pass these two textbox value in a context key..
If you have any idea please help to solve this problem.
Use ContextKey property to pass the value of textbox into GetAutoCompleteValues function.
txtbox1.Attributes.Add("onchange", "$find('BehaviourIDOftbxAttributeDesc').set_contextKey(tbxAttribute.value);");
For more information check the below links:
AJAX C# AutoCompleteExtender contextKey
http://arrao4u.wordpress.com/2010/01/14/autocomplete-extender-with-context-key/
This is the Solution which i found.
I use JavaScript:
function SetContextAbbr(formatid, itemValue, behaveid) {
var autoComplete1 = $find(behaveid);
var target = autoComplete1.get_element();
var txtformatid = document.getElementById(formatid);
var txtitemValue = document.getElementById(itemValue);
var contextkeydata = txtformatid.value + "-" + txtitemValue.value;
autoComplete1.set_contextKey(contextkeydata);
}
Use Function as
public string[] GetItemabbr(string prefixText, int count, string contextKey)
{
string[] splitvalue = contextKey.Split('-');
//code here
}
In WebService
autoabbr = new AjaxControlToolkit.AutoCompleteExtender();
autoabbr.ID = "autoabbr" + i;
autoabbr.BehaviorID = "autoabbrbehave" + i;
autoabbr.ServicePath ="itemvaluemas.asmx";
autoabbr.ServiceMethod = "GetItemabbr";
autoabbr.TargetControlID = txtItemAbbrValue.ID;
autoabbr.MinimumPrefixLength = 1;
autoabbr.CompletionInterval = 10;
autoabbr.FirstRowSelected = true;
autoabbr.CompletionListCssClass = "completionList";
autoabbr.CompletionListHighlightedItemCssClass = "itemHighlighted";
autoabbr.CompletionListItemCssClass = "listItem";
autoabbr.CompletionSetCount = 30;
autoabbr.UseContextKey = true;