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;
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'm new in c# , but i can do the basics. i need to change all the values of a column and then update the datagrid. The values are in 20170202 format and i want them like 2017-02-02. the method i did works fine but when i try to set the value to the column it wont change.
here is the code:
private void fixAlldates(DataGridView dataGridView2)
{
string aux1 = "";
for (int x = 0; x < dataGridView2.Rows.Count; x++)
{
if (dataGridView2.Rows[x].Cells[4].Value.ToString() != null)
{
aux1 = dataGridView2.Rows[x].Cells[4].Value.ToString();
dataGridView2.Rows[x].Cells[4].Value = fixDate(aux1);
}
if (dataGridView2.Rows[x].Cells[5].Value.ToString() != null)
{
dataGridView2.Rows[x].Cells[5].Value = fixDate(dataGridView2.Rows[x].Cells[5].Value.ToString());
}
dataGridView2.Refresh();
MessageBox.Show(fixDate(aux1); ----> shows result like i want ex: 2017-02-02
MessageBox.Show(dataGridView2.Rows[x].Cells[4].Value.ToString()); ----> shows 2070202
}
}
private string fixDate(string p)
{
if (p == null) return "No especificado";
String fecha = "" + p.Substring(0, 4) + "-" + p.Substring(4, 2) + "-" + p.Substring(6, 2) + "";
return fecha;
}
sorry for my bad english , im a little bit rusty
Edit:
I fill the data with bindingSource.
private void LlenarProductos(string rut)
{
this.rut = rut;
POLbindingSource1.DataSource = null;
dataGridView2.DataSource = null;
DataClasses1DataContext dc = new DataClasses1DataContext();
dc.CommandTimeout = 0;
System.Data.Linq.Table<ASE_PRODUCTOASEGURADO> producto = dc.GetTable<ASE_PRODUCTOASEGURADO>();
var todoprod = from p in producto
where p.RUT == int.Parse(rut)
select new
{
p.POLIZA,
p.SOCIO,
p.SUCURSAL,
p.COD_PROPUESTA,
p.FECHA_ALTA_COTI,
p.FECHA_ALTA_VCTO,
p.NOMBRE_PRODUCTO
};
POLbindingSource1.DataSource = todoprod; // binding source
dataGridView2.DataSource = POLbindingSource1; // filll
this.dataGridView2.Columns["POLIZA"].HeaderText = "Poliza";
this.dataGridView2.Columns["Socio"].HeaderText = "Socio";
this.dataGridView2.Columns["Sucursal"].HeaderText = "Sucursal";
this.dataGridView2.Columns["COD_PROPUESTA"].HeaderText = "Propuesta";
this.dataGridView2.Columns["FECHA_ALTA_COTI"].HeaderText = "Fecha Cotizacion";
this.dataGridView2.Columns["FECHA_ALTA_VCTO"].HeaderText = "Fecha Vencimiento";
this.dataGridView2.Columns["NOMBRE_PRODUCTO"].HeaderText = "Producto";
// fixAlldates(dataGridView2);
}
From msdn https://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcell.value(v=vs.110).aspx.
The Value property is the actual data object contained by the cell.
So basically the line MessageBox.Show(dataGridView2.Rows[x].Cells[4].Value.ToString()); is getting the value of the underlying data, whereas MessageBox.Show(fixDate(aux1); is actually formatting the date as you require.
You're overlooking the fact that although you're seeing the data in the grid in a specific way, you're not actually changing the data itself.
UPDATE
To actually edit the data in a cell see here
Actually, i have two data tables. Here is the code for reference. Actually Relationship holds the sub string values(Code not mentioned here). So i am splitting the data's to store in two table's based on the condition.
if (child.Relationship.Contains("P"))
{
var newRow = dataTable.NewRow();
newRow["EmployeeNo"] = child.EmployeeNo;
newRow["FirstName"] = child.FirstName;
newRow["MiddleName"] = child.MiddleName;
newRow["LastName"] = child.LastName;
newRow["FullName"] = child.FullName;
newRow["MemberIc"] = child.MemberIc;
dataTable.Rows.Add(newRow);
}
else
{
var newRow1 = dataTable1.NewRow();
newRow1["EmployeeNo"] = child.EmployeeNo;
newRow1["FirstName"] = child.FirstName;
newRow1["MiddleName"] = child.MiddleName;
newRow1["LastName"] = child.LastName;
newRow1["FullName"] = child.FullName;
newRow1["MemberIC"] = child.MemberIC;
dataTable1.Rows.Add(newRow1);
}
So, whenever the MemberIc in the second data table is empty. I need to copy the MemberIc from first data table(only if EmployeeNo Matches) based on the EmployeeNo.
How can i copy the value ? Any help appreciated. Thanks in advance !!!
Here you go.
var rows = datatable.Select("EmployeeNo = " + child.EmployeeNo);
var memberIC = 0;
if(rows.length > 0)
{
memberIC = rows[0].Field<int>("memberIC");
}
if (child.Relationship.Contains("P"))
{
var newRow = dataTable.NewRow();
newRow["EmployeeNo"] = child.EmployeeNo;
newRow["FirstName"] = child.FirstName;
newRow["MiddleName"] = child.MiddleName;
newRow["LastName"] = child.LastName;
newRow["FullName"] = child.FullName;
newRow["MemberIc"] = child.MemberIc;
dataTable.Rows.Add(newRow);
}
else
{
var newRow1 = dataTable1.NewRow();
newRow1["EmployeeNo"] = child.EmployeeNo;
newRow1["FirstName"] = child.FirstName;
newRow1["MiddleName"] = child.MiddleName;
newRow1["LastName"] = child.LastName;
newRow1["FullName"] = child.FullName;
newRow1["MemberIC"] = child.MemberIC == 0 ? memberIC : child.MemberIC;
dataTable1.Rows.Add(newRow1);
}
This has nothing to do with C#, ADO.NET or datatable. This is a simple logic of what to check and where to check.
I have this program where I want to create a button base from Products on my database(ProductTbl). I found a way to do that
Here's the code:
public void DynamicButton() //Function for retrieving record and creating a button for each product
{
string select = "select ProductID,ProductDesc,ProductPrice,ProductPic from ProductTbl" ;
sda = new SqlDataAdapter(select,sqlConn);
sda.Fill(dataTable);
for (int i = 0; i < dataTable.Rows.Count; i++)
{
ExtendedButton prodBtn = new ExtendedButton(); //with ExtendedButton this time
prodBtn._itemName = dataTable.Rows[i][1].ToString();//this asigns the product name to the extended button
prodBtn._itemID = Convert.ToInt32(dataTable.Rows[i][0]);
prodBtn._myPrice = Convert.ToDecimal(dataTable.Rows[i][2]);
prodBtn.BackgroundImageLayout = ImageLayout.Stretch;
prodBtn.Click += new EventHandler(OnButtonClick);
prodBtn.Height = 100;
prodBtn.Width = 100;
System.Drawing.Font f1 = SystemFonts.DefaultFont;
prodBtn.Font = new System.Drawing.Font(f1.FontFamily,f1.Size,FontStyle.Bold);
prodBtn.Text = dataTable.Rows[i][1].ToString();
prodBtn.TextAlign = ContentAlignment.BottomCenter;
prodBtn.ForeColor = Color.White;
prodBtn.BackgroundImageLayout = ImageLayout.Zoom;
toolTip1.Show(prodBtn.Text, prodBtn);
byte[] image = (byte[])dataTable.Rows[i][3];
prodBtn.BackgroundImage = imgConverter.byteArrayToImage(image);
prodBtn.TextAlign = ContentAlignment.MiddleCenter;
flowPanel.Controls.Add(prodBtn);
}
}
//You can see this at codeproject
Now the problem is that whenever i add a product on that table using Stored procedure. I don't know how i can sync updates to the datatable that I use with this one. Any ideas and suggestion will be highly appreciated. Thanks sorry for the long post
You can use ASP.Net Caching with SqlCacheDependency.
See this page for details:
https://msdn.microsoft.com/en-us/library/ms178604.aspx
I'am having simple problem with DevExpress LookUpEdit DisplayFormat. I want to achieve results in lookUpEdit like:
Document type (.doc)
Document type (.docx)
const string defaultExtensionsList = "doc;docx;xlsx;xls;pdf;txt";
//...
var column = new LookUpColumnInfo("Column", "Extensions")
{
Visible = true,
//FormatType = FormatType.Custom,
//FormatString ="Document type (*.{0})",
Alignment = HorzAlignment.Near
};
ExtensionsLookup.Properties.DisplayFormat.FormatType = FormatType.Custom;
ExtensionsLookup.Properties.DisplayFormat.FormatString = "Document type (*.{0})";
ExtensionsLookup.Properties.EditFormat.FormatType = FormatType.Custom;
ExtensionsLookup.Properties.EditFormat.FormatString = "Document type (*.{0})";
ExtensionsLookup.Properties.Columns.Add(column);
var bindingList = defaultExtensionsList.Split(';').ToList();
ExtensionsLookup.Properties.DataSource = bindingList;
You can use the following trick (RepositoryItemLookUpEdit.GetNotInListValue event):
const string defaultExtensionsList = "doc;docx;xlsx;xls;pdf;txt";
//...
var columnID = new LookUpColumnInfo("Column", "IDs") { Visible = false };
var columnToDisplay = new LookUpColumnInfo("Display", "Extensions");
lookUpEdit.Properties.Columns.AddRange(new LookUpColumnInfo[] { columnID, columnToDisplay });
lookUpEdit.Properties.ValueMember = "Column";
lookUpEdit.Properties.DisplayMember = "Display";
lookUpEdit.Properties.TextEditStyle = TextEditStyles.DisableTextEditor;
lookUpEdit.Properties.GetNotInListValue += OnGetNotInListValue;
var bindingList = defaultExtensionsList.Split(';').ToList();
lookUpEdit.Properties.DataSource = bindingList;
//...
void OnGetNotInListValue(object sender, GetNotInListValueEventArgs e) {
if(e.FieldName == "Display")
e.Value = string.Format("Document type (*.{0})",
((IList<string>)lookUpEdit.Properties.DataSource)[e.RecordIndex]);
}
If I remember correctly, LookUpEdit doesn't support this functionality.
I would simply build a List with values "Document type (.docx)", "Documentype (.xy)" and bind it to the control.
Something like
var types = defaultExtensionsList.Split(';').Select(s => "DocumentType (*." + s + ")").ToList();