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();
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?
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");
Due to a flaw in .NET (Microsoft says its intended but I see it as a serious flaw)
If a user empties a combo box (i.e. wants to blank out the value) the selected value does not revert to null instead it keeps the last valid selected value, so when you save with a blank combobox it goes back to the original value.One workaround is to first choose a different option from the drop down, then blank it out and it will work properly. However, that's not something users of an application would prefer.
So is there a way that I can fix this. Or is it possible that I can add an option for "NONE" which will then change the value in the database to NULL. Note: Combobox has data-binding and I was not able to add the option none for Names.
Contents of the Form.Desginer.cs:
private void InitializeComponent()
{
......
this.cmbSecCSR = new System.Windows.Forms.ComboBox();
this.csrBindingSource2 = new System.Windows.Forms.BindingSource(this.components);
.....
//
// pnlCSRs
//
this.pnlCSRs.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.pnlCSRs.Controls.Add(this.cmbSecCSR);
......
//
// cmbSecCSR
//
this.cmbSecCSR.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.SuggestAppend;
this.cmbSecCSR.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.ListItems;
this.cmbSecCSR.DataSource = this.csrBindingSource2;
this.cmbSecCSR.DisplayMember = "Name";
this.cmbSecCSR.FormattingEnabled = true;
this.cmbSecCSR.Location = new System.Drawing.Point(112, 26);
this.cmbSecCSR.Margin = new System.Windows.Forms.Padding(0);
this.cmbSecCSR.Name = "cmbSecCSR";
this.cmbSecCSR.Size = new System.Drawing.Size(184, 21);
this.cmbSecCSR.TabIndex = 2;
this.cmbSecCSR.ValueMember = "Username";
this.cmbSecCSR.TextChanged += new System.EventHandler(this.comboBox_TextChanged);
this.cmbSecCSR.Enter += new System.EventHandler(this.cmbBox_Entered);
//
// csrBindingSource2
//
this.csrBindingSource2.DataMember = "CSR";
this.csrBindingSource2.DataSource = this.productionDS;
//..............
}
Above are the bits and pieces related to this combobox (I'm just fixing bugs in the application, and a newbie in C#.
The contents related to this combobox in the .CS file are the following:
private void loadDetails()
{
this.productionCrewTableAdapter.FillByProductionID(this.productionDS.ProductionCrew, productionID);
cmbSecCSR.DataBindings.Add("SelectedValue", productionMasterBindingSource, "CSR2", true, DataSourceUpdateMode.OnPropertyChanged);
}
private void comboBox_TextChanged(object sender, EventArgs e)
{
ComboBox cmbx = (ComboBox)sender;
if (cmbx.Equals(cmbCamSupplier))
{
}
else if (cmbx.Equals(cmbLGSupplier))
{
}
if (cmbx.Text.Length > 0) return;
cmbx.ResetText();
cmbx.SelectedIndex = -1;
}
private void cmbBox_Entered(object sender, EventArgs e)
{
ComboBox cmb = (ComboBox)sender;
String txt = cmb.Text;
if (cmb.Name.Contains("CSR"))
{
if (cmb != null)
{
((BindingSource)cmb.DataSource).Filter = (cmbOffice.SelectedIndex > -1 ? "Office = '" + cmbOffice.SelectedValue + "' AND " : "") + "IsCSR=1 AND Status=1";
cmb.Text = txt;
}
}
else if (cmb.Name.Contains("RC"))
{
int department = 0;
if (cmb != null)
{
if (cmb.Name.Contains("Camera"))
department = 2;
else if (cmb.Name.Contains("LG"))
department = 3;
else if (cmb.Name.Contains("Power"))
department = 4;
((BindingSource)cmb.DataSource).Filter = (cmbOffice.SelectedIndex > -1 ? "Office = '" + cmbOffice.SelectedValue + "' AND " : "") + "IsCSR=0 AND Status=1 AND (Department = " + department + " OR Department is null OR Department = 0)";
cmb.Text = txt;
}
}
}
If anyone can help me with this issue that I have been struggling with for a while, I'd really really appreciate it.
At the same time to your call clearing values with
this.cmbSecCSR.Items.Clear()
You have to do a
this.cmbSecCSR.Text = ""
or
this.cmbSecCSR.Text = "Default Text"
To clear the selected text in the combobox.
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;
I have a treeview and i want no postback on click any childnodes.And i will get selected childnode value.
I found a solution , when i set "node_.SelectAction = TreeNodeSelectAction.None;" i cant select any childnodes and no highlight on it.
Waiting your helps.Sorry about my en.
Aspx:
<asp:TreeView ID="TreeView1" runat="server"></asp:TreeView>
Cs:
TreeView1.Nodes.Clear();
TreeView1.TreeNodeExpanded += new TreeNodeEventHandler(TreeView1_TreeNodeExpanded);
DataTable dt = ImzaDll.Imza.KategorileriGetir(true);
foreach (DataRow row in dt.Rows)
{
TreeNode node_ = new TreeNode();
node_.Text = row["ACIKLAMA"].ToString();
node_.Value = row["KATEGORI"].ToString();
TreeView1.Nodes.Add(node_);
}
void TreeView1_TreeNodeExpanded(object sender, TreeNodeEventArgs e)
{
addChildNodes(e.Node);
}
private void addChildNodes(TreeNode node)
{
DataTable dt = ImzaDll.Imza.KutuphaneBasliklariGetir(true, node.Value.ToString());
foreach (DataRow row in dt.Rows)
{
TreeNode childNode = new TreeNode();
childNode.Text = row["BASLIK"].ToString();
childNode.Value = row["KUTUPHANE_ID"].ToString();
childNode.ToolTip = row["BASLIK"].ToString() + " kütüphanesini ekle";
childNode.Target = "_new";
node.ChildNodes.Add(childNode);
}
}
You can set CSSClass of treeview child nodes
like
<asp:TreeView LeafNodeStyle-CssClass="childnode" runat="server">....</asp:TreeView>
then using jquery you get get class and set return false like follow.
$(".childnode").click(function(){
return false;
})
...same way you can set RootNodeStyle-CssClass, ParentNodeStyle-CssClass class and use jquery to set them...
TreeNode tn = new TreeNode();
tn.SelectAction = TreeNodeSelectAction.None; OR tn.SelectAction = TreeNodeSelectAction.Expand;
Both of these will not cause postback.
you could remove the href of link('a') tag attribute to stop post back
$('#ctl00_ContentPlaceHolder1_tvHierarchyView table tr td>a').click(function () {
var treeViewData = window["<%=tvHierarchyView.ClientID%>" + "_Data"];
if (treeViewData.selectedNodeID.value != "") {
var selectedNode=document.getElementById(treeViewData.selectedNodeID.value);
var value = selectedNode.href.substring(selectedNode.href.indexOf(",") + 3, selectedNode.href.length - 2);
var text = selectedNode.innerHTML;
alert("Text: " + text + "\r\n" + "Value: " + value);
} else {
alert("No node selected.")
}
$(this).removeAttr("href");
/// ...................... rest of your code
}); /// End of click function
}); /// End of document ready function
Here steps explanation:
Get the dev id which contains the tree table by Using inspect element:
Get details from the selected child node.
After taken the details of child node , remove the attribute "href" to avoid post back.
Do whatever functionality you what do with selected node details (eg pass selected value using ajax)