After some minor difficulties with my basic test rating control not working because of the missing inline CSS stylesheet, I am trying to dynamically add a bunch of rating controls in a updatepanel when I click on a button in a different updatepanel. (These panels are both in a parent updatepanel, I have defined the triggers and set the updatemode to conditional). Anyways, when I click the button, he updates the updatepanel with the rating controls, but when I hover over them, he always displays 0 (the current rating), and does not change the rating control star image (filledStarRating). The code relevant to my problem (two methods):
protected void imbformulier_Click(Object sender, ImageClickEventArgs e)
{
imbFormulier.Visible = false;
imbGebruikers.Visible = false;
imbModellen.Visible = false;
pnlGegevens1.Visible = false;
pnlGegevens2.Visible = true;
pnlNavigatie.Visible = true;
pnlEval.Visible = true;
//kijken welk formulier moet ingevuld worden adhv de ddl's en dit meegeven aan de zelfgemaakte klasse
List<EvaluatieFormulier> mijnformulieren = (List<EvaluatieFormulier>)Session["mijnformulieren"];
IEnumerator<EvaluatieFormulier> enumerator = mijnformulieren.GetEnumerator();
EvaluatieFormulier meetegeven = new EvaluatieFormulier();
while (enumerator.MoveNext())
{
if (((enumerator.Current.GebruikergeevalueerdID == ddlGebruikers.SelectedValue) && (enumerator.Current.ModelID == Convert.ToInt32(ddlModellen.SelectedValue))))
{
meetegeven = enumerator.Current;
//Eventueel tekst veranderen als er al was gewerkt aan een bepaalde evaluatie
if (meetegeven.Tijdaangewerkt == 0)
{
lblInfo.Text = "Evaluatie gestart van " + ddlGebruikers.SelectedItem.Text;
lblDatum.Text = "Evaluatie begonnen op: "+ DateTime.Now.Date.ToString("d/M/yyyy") + "(Vandaag)" ;
//updaten in database
Session["aantalminutenaangewerkt"] = 0;
Session["aantalsecondenaangewerkt"] = 0;
timTijdAanGewerkt.Enabled = true;
lblTijd.Visible = true;
}
else
{
lblInfo.Text = "Evaluatie verdergezet van " + ddlGebruikers.SelectedItem.Text;
lblDatum.Text = "Evaluatie laatst gewijzigd : " + meetegeven.Tijdingevuld.ToString();
Session["aantalminutenaangewerkt"] = meetegeven.Tijdaangewerkt;
Session["aantalsecondenaangewerkt"] = 0;
timTijdAanGewerkt.Enabled = true;
lblTijd.Visible = true;
}
}
}
//Rating controls aanmaken voor elke criteria
List<AjaxControlToolkit.Rating> lijstratingcontrols = new List<AjaxControlToolkit.Rating>();
Model modelmetdomeinen = new Model() ;
IEnumerator<Model> modelenum = Database.laadModellenIn().GetEnumerator();
while (modelenum.MoveNext())
{
if (modelenum.Current.ModelID == meetegeven.ModelID)
modelmetdomeinen = modelenum.Current;
}
//foreach (Domein domein in modelmetdomeinen.Domeins)
//{
// foreach (Criterium criterium in domein.Criteriums)
// {
// AjaxControlToolkit.Rating ratingcontrol = new AjaxControlToolkit.Rating();
// ratingcontrol.ID = criterium.CriteriumNaam;
// ratingcontrol.StarCssClass = "ratingStar";
// ratingcontrol.EmptyStarCssClass = "emptyStarRating";
// ratingcontrol.WaitingStarCssClass = "emptyStarRating";
// ratingcontrol.FilledStarCssClass = "filledStarRating";
// ratingcontrol.Changed += new AjaxControlToolkit.RatingEventHandler(rating_Changed);
// ToolkitScriptManager1.RegisterAsyncPostBackControl(ratingcontrol);
// lijstratingcontrols.Add(ratingcontrol);
// }
//}
//Evaluatieform formulier = new Evaluatieform(meetegeven,lijstratingcontrols);
Table evaluatietabel = new Table();
int domeinteller =0;
foreach (Domein domein in modelmetdomeinen.Domeins)
{
domeinteller++;
if (domeinteller < 4)
{
TableRow domeinrij = new TableRow();
TableCell domeintitel = new TableCell();
domeintitel.Text = domeinteller + ". " + domein.DomeinNaam;
domeintitel.BorderStyle = BorderStyle.None;
domeinrij.Cells.Add(domeintitel);
evaluatietabel.Rows.Add(domeinrij);
foreach (Criterium criterium in domein.Criteriums)
{
int criteriumteller = 1;
TableRow criteriumrij = new TableRow();
TableCell criteriumtitel = new TableCell();
TableCell opvulcell = new TableCell();
TableCell ratingcell = new TableCell();
criteriumtitel.BorderStyle = BorderStyle.None;
opvulcell.BorderStyle = BorderStyle.None;
ratingcell.BorderStyle = BorderStyle.None;
criteriumtitel.Text = criteriumteller + ". " + criterium.CriteriumNaam;
AjaxControlToolkit.Rating ratingcontrol = new AjaxControlToolkit.Rating();
ratingcontrol.ID = criterium.CriteriumNaam;
ratingcontrol.StarCssClass = "ratingStar";
ratingcontrol.EmptyStarCssClass = "emptyStarRating";
ratingcontrol.WaitingStarCssClass = "emptyStarRating";
ratingcontrol.FilledStarCssClass = "filledStarRating";
ratingcontrol.Changed += new AjaxControlToolkit.RatingEventHandler(rating_Changed);
ratingcell.Controls.Add(ratingcontrol);
ratingcell.Attributes.Add("runat", "server");
ratingcell.Attributes.Add("onclick", "return false");
criteriumrij.Cells.Add(opvulcell);
criteriumrij.Cells.Add(criteriumtitel);
criteriumrij.Cells.Add(ratingcell);
evaluatietabel.Rows.Add(criteriumrij);
criteriumteller++;
}
}
}
evaluatietabel.BorderStyle = BorderStyle.None;
pnlEval.ContentTemplateContainer.Controls.Add(evaluatietabel);
Session["formulieractief"] = true;
pnlEval.Update();
pnlGegevens1.Update();
pnlGegevens2.Update();
}
I'm also adding the link to an image that shows my problem, so that you can see it for yourself:
We had the same issue recently and the problem was that the latest version of the AjaxControltoolkit seems to require a ToolkitScriptManager instead of the normal ScriptManager.
So just try changing your
asp:ScriptManager tag to
asp:ToolKitScriptManager or
ajax:ToolKitScriptManager
or whatever your namespace is.
Related
everybody,
I have been trying for days now to solve this problem with no success.
I have textboxes in table cells which are created dynamically upon button click. Three of these buttons will take a value, calculation method (% or Const Value) and the value to apply respectively. Below is the function which creates these TB's among other controls.
protected void btnAddService_Click(object sender, EventArgs e)
{
TableRow r = new TableRow();
TableCell c0 = new TableCell();
TableCell c1 = new TableCell();
TableCell c2 = new TableCell();
TableCell c3 = new TableCell();
TableCell c4 = new TableCell();
TableCell c5 = new TableCell(); // Management Fees (% or Const)
TableCell c6 = new TableCell(); // Management Fees Value
TableCell c7 = new TableCell(); // Remarks
service s = new service();
if (serCount == 0)
{
tblHeader.Visible = true;
}
// Add the Services DropDownList...
DropDownList ddlS = new DropDownList();
ddlS.ID = "ddlServices" + serCount;
ddlS.Items.Add("Management");
ddlS.Items.Add("MEP");
ddlS.Items.Add("Landscaping");
ddlS.Items.Add("Pest Control");
ddlServices.Add(ddlS);
ddlS.CssClass = "form-control";
ddlS.Width = Unit.Percentage(100);
c0.Controls.Add(ddlS);
c0.Width = Unit.Percentage(15);
s.serviceName = "Management";
// Add Subcontracted Checkbox...
CheckBox chkSubCont = new CheckBox();
chkSubCont.ID = "chkSubCont" + serCount;
chkSubContracted.Add(chkSubCont);
c1.Controls.Add(chkSubCont);
c1.Width = Unit.Percentage(5);
c1.HorizontalAlign = HorizontalAlign.Center;
s.subcontracted = false;
// Add Subcontracted Value...
TextBox txtSubContVal = new TextBox();
txtSubContVal.ID = "txtSubcontractVal" + serCount;
txtSubContVal.CssClass = "form-control";
txtSubContVal.Attributes.Add("placeholder", "0.000");
txtSubContVal.Style.Add("text-align", "right");
txtSubcontValue.Add(txtSubContVal);
c2.Controls.Add(txtSubContVal);
c2.Width = Unit.Percentage(10);
s.subcontValue = 0;
// Add Management Fees Type (% or Const)...
DropDownList ddlMFT = new DropDownList();
ddlMFT.Items.Add("%");
ddlMFT.Items.Add("Value");
ddlMFT.CssClass = "form-control";
ddlMFT.Width = Unit.Percentage(100);
ddlMFT.ID = "ddlManFeesType" + serCount;
ddlManFeesType.Add(ddlMFT);
c5.Controls.Add(ddlMFT);
c5.Width = Unit.Percentage(5);
// Add Management Fees Value...
TextBox txtMFVal = new TextBox();
txtMFVal.CssClass = "form-control";
txtMFVal.Attributes.Add("placeholder", "0.000");
txtMFVal.Style.Add("text-align", "right");
txtMFVal.Width = Unit.Percentage(100);
// txtMFVal.ID = "txtManFeesValue" + serCount;
txtMFVal.AutoPostBack = true;
txtMFVal.TextChanged += new EventHandler(txtManFeesVal_TextChange);
txtManFeesValue.Add(txtMFVal);
c6.Controls.Add(txtMFVal);
c6.Width = Unit.Percentage(10);
// Add Manpower Value...
TextBox txtManp = new TextBox();
txtManp.ID = "txtManpower" + serCount;
txtManp.CssClass = "form-control";
txtManp.Attributes.Add("placeholder", "0");
txtManp.Style.Add("text-align", "center");
txtManPower.Add(txtManp);
c3.Controls.Add(txtManp);
c3.Width = Unit.Percentage(10);
s.manPower = 0;
// Add Quoted Value...
TextBox txtQuotVal = new TextBox();
txtQuotVal.ID = "txtQuotedValue" + serCount;
txtQuotVal.CssClass += "form-control";
// txtQuotVal.Text = "0.000";
txtQuotVal.Attributes.Add("placeholder", "0.000");
txtQuotVal.Style.Add("text-align", "right");
txtQuotVal.AutoPostBack = true;
txtQuotVal.ClientIDMode = ClientIDMode.Static;
txtQuotVal.TextChanged += (o, ep) => {
TextBox t = sender as TextBox;
if (t.Text == "")
{
t.Text = "0.000";
}
txtPrjValue.Text = (int.Parse(txtPrjValue.Text) + int.Parse(t.Text)).ToString();
};
txtQuotValue.Add(txtQuotVal);
c4.Controls.Add(txtQuotVal);
c4.Width = Unit.Percentage(10);
// Add Remarks Box...
TextBox txtRem = new TextBox();
txtRem.ID = "txtRemarks" + serCount;
txtRem.CssClass += "form-control";
txtRem.ClientIDMode = ClientIDMode.Static;
txtRem.Width = Unit.Percentage(100);
txtRemarks.Add(txtRem);
c7.Controls.Add(txtRem);
c7.Width = Unit.Percentage(35);
s.quotedValue = 0;
// Add the cells to the new row...
r.Cells.Add(c0);
r.Cells.Add(c1);
r.Cells.Add(c2);
r.Cells.Add(c5);
r.Cells.Add(c6);
r.Cells.Add(c3);
r.Cells.Add(c4);
r.Cells.Add(c7);
// Add the new row...
tblServices.Rows.Add(r);
serCount++;
// Postback to refresh contents from Server Side...
string scriptRefresh = "document.getElementById('" + btnASPClickMe.ClientID + "').click();";
Page.ClientScript.RegisterStartupScript(typeof(Page), "refreshscript", scriptRefresh, true);
}
Upon TextChanged of txtMFVal text, it does PostBack but it doesn't call the attached event handler, shown below:
protected void txtManFeesVal_TextChange(object sender, EventArgs e)
{
TextBox txtMFV = sender as TextBox;
// Get the parent cell of the TextBox...
TableRow tr = txtMFV.Parent.Parent as TableRow;
TextBox txtSCV = tr.Cells[2].Controls[0] as TextBox;
TextBox txtMFT = tr.Cells[5].Controls[0] as TextBox;
double scv = Double.Parse(txtSCV.Text);
double mfv = Double.Parse(txtMFV.Text);
double v = 0;
if (txtMFT.Text == "%")
{
v = (scv * mfv) / 100;
}
else
{
v = scv + mfv;
}
TextBox txtQP = tr.Cells[6].Controls[0] as TextBox;
txtQP.Text = v.ToString();
// Postback to refresh contents from Server Side...
string scriptRefresh = "document.getElementById('" + btnASPClickMe.ClientID + "').click();";
Page.ClientScript.RegisterStartupScript(typeof(Page), "refreshscript", scriptRefresh, true);
}
I have tried so many tricks I have found on the net and all didn't work.
Please, help.
Thanks,
I'm calling a function from another class to a form to load datagridView. when i add only one dataGirdViewButtonColumn its works but when i add two the second one is not added.Another problem i have found is the button is added to empty row..
Function
public void LoadDataGridrcv(DataTable d, DataGridView dg)
{
DataGridViewButtonColumn btn = new DataGridViewButtonColumn();
DataGridViewButtonColumn btn1 = new DataGridViewButtonColumn();
if (dg.InvokeRequired)
{
dg.BeginInvoke((MethodInvoker)delegate()
{
dg.Rows.Clear();
dg.ColumnCount = 7;
dg.Columns[0].Name = "Order No.";
dg.Columns[0].Width = 110;
dg.Columns[1].Name = "Order Date";
dg.Columns[1].Width = 100;
dg.Columns[2].Name = "Excepted rcv date";
dg.Columns[2].Width = 100;
dg.Columns[3].Name = "Supplier";
dg.Columns[3].Width = 150;
dg.Columns[4].Name = "Total Items";
dg.Columns[4].Width = 80;
dg.Columns[5].Name = "Total";
dg.Columns[5].Width = 80;
dg.Columns[6].Name = "Status";
dg.Columns[6].Width = 100;
dg.Columns.Add(btn);
btn.HeaderText = "Click to view";
btn.Text = "View";
btn.Name = "btn";
btn.UseColumnTextForButtonValue = true;
btn1.HeaderText = "Click to recieve";
btn1.Text = "Recieve";
btn1.Name = "btn1";
btn1.UseColumnTextForButtonValue = true;
});
foreach (DataRow row in d.Rows)
{
if (dg.InvokeRequired)
{
dg.BeginInvoke((MethodInvoker)delegate() { dg.Rows.Add(row[0].ToString(), row[1].ToString(), row[2].ToString(), row[3].ToString(), row[4].ToString(), row[5].ToString(), row[6].ToString()); });
}
Thread.Sleep(100);
}
}
}
Usage
reatail r = new reatail();
t = new Thread(() => r.LoadDataGridrcv(r.loadAllOrder(), dataGridView1));
t.Start();
Well i'm working an application which use a connection with SharePoint to load the list items.
I'm also using a dynamic table so new rows can be added by the user.
It takes more than 7 seconds before my page is asp.net page. I checked this with firebug.
Below is the code of my page:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Client;
namespace AdminCareWeb
{
public partial class DocumentToevoegen : System.Web.UI.Page
{
#region globalevars
SharePointContextToken contextToken;
string accessToken;
Uri sharepointUrl;
string contextTokenString;
string logoHoofding;
int initNumRows = 15;
public string jsSharePointURL;
//Instanties aanmaken van de klasses
static List<TableRow> TableRows = new List<TableRow>();
static Dictionary<int, Artikels> dicArtikels = new Dictionary<int, Artikels>();
Document huidigDocument = new Document();
Klanten huidigeKlant = new Klanten();
#endregion
#region properties
private int numOfRows
{
get
{
if (ViewState["RowsCount"] == null)
{
return 0;
}
else
{
return (int)ViewState["RowsCount"];
}
}
set
{
ViewState["RowsCount"] = value;
}
}
#endregion
protected void Page_Load(object sender, EventArgs e)
{
try
{
string vorigePagina = Request.UrlReferrer.ToString();
//Controleer of de pagina gerefreshd werd of voor het eerst geladen wordt.
if (!vorigePagina.Contains("DocumentToevoegen.aspx"))
{
TableRows.Clear();
//Als de pagina voor de eerste keer geladen wordt moet de tabel leeggemaakt worden.
dicArtikels.Clear();
}
//Generate the Rows on Initial Load
if (!Page.IsPostBack && dicArtikels.Count == 0)
{
numOfRows = initNumRows;
Artikels artikel = new Artikels();
for (int i = 0; i < numOfRows; i++)
{
dicArtikels.Add(i, artikel);
}
}
GenerateTable(0, numOfRows);
//Controleer of security tokens al aanwezig zijn. Indien deze niet aanwezig zijn maak ze globaal aan.
if (PassThrough.contextTokenString != null)
{
ClientContext clientContext = ContextTokensOphalen();
jsSharePointURL = PassThrough.sharepointUrl.ToString();
}
else if (!IsPostBack)
{
Response.Write("Could not find a context token.");
return;
}
}
catch (Exception ex)
{
huidigDocument.log("DocumentToevoegen.aspx", "Page_Load", ex.Message.ToString());
}
}
protected void Page_LoadComplete(object sender, EventArgs e)
{
ClientContext clientContext = ContextTokensOphalen();
try
{
bool foutief = false; ;
string adresgegevens = "";
#region parameters ophalen
Parameters ledig = new Parameters();
ledig.ledigParameters();
huidigDocument.ParametersLookup(clientContext);
huidigDocument.Parameters1Tekstregel(clientContext);
huidigDocument.ParametersMeerdereTekstregels(clientContext);
huidigDocument.ParametersJaNeen(clientContext);
//Controleer of de bankgegevens ingevuld werden.
if (Parameters.Bankgegevens != null && !string.IsNullOrEmpty(Parameters.Bankgegevens))
{
foutief = false;
lblBankgegevens.Text = Parameters.Bankgegevens.Replace("\r\n", "<br />");
}
if (Parameters.Naam != null && !string.IsNullOrEmpty(Parameters.Naam))
{
foutief = false;
adresgegevens += Parameters.Naam + "<br>";
}
if (Parameters.Adres != null && !string.IsNullOrEmpty(Parameters.Adres))
{
foutief = false;
adresgegevens += Parameters.Adres + "<br>";
}
if (Parameters.Adres2 != null && !string.IsNullOrEmpty(Parameters.Adres2))
{
foutief = false;
adresgegevens += Parameters.Adres2 + "<br>";
}
if (Parameters.Postcode != null && !string.IsNullOrEmpty(Parameters.Postcode))
{
foutief = false;
adresgegevens += Parameters.Postcode;
}
if (Parameters.Plaats != null && !string.IsNullOrEmpty(Parameters.Plaats))
{
foutief = false;
adresgegevens += " " + Parameters.Plaats + "<br>";
}
if (Parameters.Telefoon != null && Parameters.Telefoon.Length > 3)
{
foutief = false;
adresgegevens += "Tel: " + Parameters.Telefoon + "<br>";
}
if (Parameters.GSM != null && Parameters.GSM.Length > 3)
{
foutief = false;
adresgegevens += "GSM: " + Parameters.GSM + "<br>";
}
if (Parameters.Fax != null && Parameters.Fax.Length > 3)
{
foutief = false;
adresgegevens += "Fax: " + Parameters.Fax + "<br>";
}
if (Parameters.Ondernemingsnummer != null && Parameters.Ondernemingsnummer.Length > 3)
{
foutief = false;
adresgegevens += "BTW " + Parameters.Ondernemingsnummer + "<br>";
}
if (Parameters.RPR != null && !string.IsNullOrEmpty(Parameters.RPR))
{
foutief = false;
adresgegevens += "RPR " + Parameters.RPR + "<br>";
}
if (Parameters.Website != null && !string.IsNullOrEmpty(Parameters.Website))
{
foutief = false;
adresgegevens += Parameters.Website + "<br>";
}
if (Parameters.Email != null && !string.IsNullOrEmpty(Parameters.Email))
{
foutief = false;
adresgegevens += Parameters.Email + "<br>";
}
if (Parameters.Logo != null && Parameters.LogoHoofding.ToString() == "")
{
foutief = false;
imgLogo.ImageUrl = Parameters.Logo;
imgLogo.Visible = true;
}
if (Parameters.LogoHoofding.ToString() != "")
{
logoHoofd.Style.Add("BACKGROUND-IMAGE", "url(" + Parameters.LogoHoofding + ");width:794px;");
foutief = false;
logoHoofding = Parameters.LogoHoofding;
imgLogo.Visible = false;
}
if (Parameters.Logovoet != null)
{
foutief = false;
imgVoet.ImageUrl = Parameters.Logovoet;
imgVoet.Visible = true;
imgVoet.Height = 140;
imgVoet.Width = 794;
}
if (!foutief) { lblAdresgegevens.Text = adresgegevens; }
#endregion
}
catch (Exception ex)
{
huidigDocument.log("DocumentToevoegen.aspx", "Page_Load", ex.Message.ToString());
}
if (!Page.IsPostBack)
{
//Huidige datum ophalen volgens het Belgisch formaat.
//Datum wordt gebruikt om de Documentdatum in te stellen en de vervaldatum.
DateTime dt = DateTime.Now;
txtDocumentDatum.Text = dt.ToString("dd-MM-yyyy");
dt = dt.AddDays(30);
txtVervaldatum.Text = Parameters.Vervaldatum;
ddlLand.SelectedValue = "20";
lblIntraCom.Text = "";
try
{
#region klanten ophalen
//Klanten invullen met de opgehaalde waardes uit een Dictionary
foreach (KeyValuePair<string, string> klant in huidigeKlant.KlantenOphalen())
{
string naam = klant.Value;
ddlKlant.Items.Add(new System.Web.UI.WebControls.ListItem(naam, naam));
}
#endregion
#region dagboeken ophalen
//Dagboeken invullen met de opgehaalde waardes uit een Dictionary
foreach (KeyValuePair<string, string> dagboeken in huidigDocument.Dagboeken())
{
//ddlDagboek.Items.Clear();
string ID = dagboeken.Key;
string omschrijving = dagboeken.Value;
ddlDagboek.Items.Add(new System.Web.UI.WebControls.ListItem(omschrijving, ID));
}
#endregion
#region postcodes ophalen
//Postcodes invullen met de opgehaalde waardes uit een Dictionary
foreach (KeyValuePair<string, string> postcode in huidigeKlant.Postcodes())
{
string ID = postcode.Key;
string gemeente = postcode.Value;
ddlGemeente.Items.Add(new System.Web.UI.WebControls.ListItem(gemeente, ID));
}
huidigDocument.DocumentNummerOpvragen(int.Parse(ddlDagboek.SelectedValue));
txtDocNr.Text = huidigDocument.documentCode + " / " + huidigDocument.huidigDocumentNummer;
#endregion
#region landen ophalen
//Landen invullen met de opgehaalde waardes uit een Dictionary
foreach (KeyValuePair<string, string> land2 in huidigeKlant.Landen())
{
string ID = land2.Key;
string land = land2.Value;
ddlLand.Items.Add(new System.Web.UI.WebControls.ListItem(land, ID));
}
huidigDocument.DocumentTitelOpvragen(int.Parse(ddlDagboek.SelectedValue));
lblDocumentTitel.Text = huidigDocument.documentTitel;
#endregion
}
catch (Exception ex)
{
huidigDocument.log("DocumentToevoegen.aspx", "Page_Load", ex.Message.ToString());
}
}
}
private void GenerateTable(int existing, int rowsCount)
{
try
{
//Alle data halen uit de PassThrough class om opnieuw een connectie te maken met SharePoint
ClientContext clientContext = ContextTokensOphalen();
Table table = Page.Form.FindControl("tblArtikels") as Table;
if (table == null)
{
table = new Table();
table.ID = "tblArtikels";
Page.Form.Controls.Add(table);
}
else
{
if (existing == 0)
{
table.Controls.Clear();
}
}
//The number of Columns to be generated
const int colsCount = 6;//You can changed the value of 3 based on you requirements
// Now iterate through the table and add your controls
for (int i = existing; i < rowsCount; i++)
{
if (!dicArtikels.ContainsKey(i))
{
Artikels artikel = new Artikels();
dicArtikels.Add(i, artikel);
}
TableRow row = new TableRow();
for (int j = 0; j < colsCount; j++)
{
TableCell cell = new TableCell();
//means the first column of the Table
if (j == 0)
{
cell.Width = 40;
//Create the CheckBox
CheckBox cb = new CheckBox();
// Set a unique ID for each CheckBox
cb.ID = "CheckBoxRow_" + i + "Col_" + j;
// Add the control to the FIRST TableCell
cell.Controls.Add(cb);
// Add the TableCell to the TableRow
row.Cells.Add(cell);
}
//2de kolom
else if (j == 1)
{
cell.Width = 60;
//Create the TextBox
TextBox tb = new TextBox();
// Set a unique ID for each TextBox
tb.ID = "TextBoxRow_" + i + "Col_" + j;
tb.Width = 40;
tb.EnableViewState = true;
tb.EnableTheming = true;
// Add the control to the TableCell
cell.Controls.Add(tb);
// Add the TableCell to the TableRow
row.Cells.Add(cell);
}
//Kolom 3
else if (j == 2)
{
cell.Width = 310;
cell.HorizontalAlign = HorizontalAlign.Right;
//Create the TextBox
TextBox tb = new TextBox();
// Set a unique ID for each TextBox
tb.ID = "TextBoxRow_" + i + "Col_" + j;
tb.Width = 290;
tb.EnableViewState = true;
tb.EnableTheming = true;
tb.TextMode = TextBoxMode.MultiLine;
// Add the control to the TableCell
cell.Controls.Add(tb);
// Add the TableCell to the TableRow
row.Cells.Add(cell);
}
//Kolom 4
else if (j == 3)
{
cell.Width = 160;
cell.HorizontalAlign = HorizontalAlign.Right;
//Create the TextBox
TextBox tb = new TextBox();
// Set a unique ID for each TextBox
tb.ID = "TextBoxRow_" + i + "Col_" + j;
//tb.TextChanged += new EventHandler(txtArtikelPrijs_TextChanged);
tb.Width = 140;
tb.EnableViewState = true;
tb.EnableTheming = true;
// Add the control to the TableCell
cell.Controls.Add(tb);
// Add the TableCell to the TableRow
row.Cells.Add(cell);
}
//Kolom 5
else if (j == 4)
{
cell.Width = 160;
cell.HorizontalAlign = HorizontalAlign.Right;
//Create the TextBox
TextBox tb = new TextBox();
// Set a unique ID for each TextBox
tb.ID = "TextBoxRow_" + i + "Col_" + j;
//tb.TextChanged += new EventHandler(txtArtikelPrijs_TextChanged);
tb.Width = 140;
tb.Enabled = false;
tb.BackColor = System.Drawing.ColorTranslator.FromHtml("#F2F2F2");
tb.TabIndex = -1;
tb.EnableViewState = true;
tb.EnableTheming = true;
// Add the control to the TableCell
cell.Controls.Add(tb);
// Add the TableCell to the TableRow
row.Cells.Add(cell);
}
//Kolom 6
else if (j == 5)
{
cell.HorizontalAlign = HorizontalAlign.Right;
cell.Width = 64;
//Create the TextBox
DropDownList ddl = new DropDownList();
// Set a unique ID for each TextBox
ddl.ID = "DropDownRow_" + i + "Col_" + j;
ddl.Width = 50;
ddl.TabIndex = -1;
ddl.EnableViewState = true;
ddl.EnableTheming = true;
ddl.Items.Clear();
//Lijst met artikelen ophalen en dropdown opvullen
List oListBTW = clientContext.Web.Lists.GetByTitle("Lijst BTWcodes");
clientContext.ExecuteQuery();
CamlQuery cQBTW = new CamlQuery();
cQBTW.ViewXml = "<View>"
+ "<Query>"
+ "</Query>"
+ "</View>";
Microsoft.SharePoint.Client.ListItemCollection btwListItem = oListBTW.GetItems(cQBTW);
clientContext.Load(btwListItem);
clientContext.ExecuteQuery();
foreach (Microsoft.SharePoint.Client.ListItem btwItem in btwListItem)
{
string btwcode = btwItem["bcCode"].ToString();
string btwpercentage = btwItem["bcBTW"].ToString();
ddl.Items.Add(new System.Web.UI.WebControls.ListItem(btwpercentage, btwcode));
}
if (i >= initNumRows && ddlBTWregime.Items.Count > 0)
{
if (ddlBTWregime.SelectedItem.Value == "Medecontractant" || ddlBTWregime.SelectedItem.Value == "intracom goederen" || ddlBTWregime.SelectedItem.Value == "intracom diensten")
{
ddl.Enabled = false;
ddl.SelectedItem.Text = "0";
ddl.BackColor = System.Drawing.ColorTranslator.FromHtml("#F2F2F2");
}
else if (ddlBTWregime.SelectedItem.Value == "BTW 6%")
{
ddl.Enabled = false;
ddl.SelectedItem.Text = "6";
ddl.BackColor = System.Drawing.ColorTranslator.FromHtml("#F2F2F2");
}
else
{
ddl.Enabled = true;
ddl.BackColor = System.Drawing.ColorTranslator.FromHtml("#FFFFFF");
}
}
// Add the control to the TableCell
cell.Controls.Add(ddl);
// Add the TableCell to the TableRow
row.Cells.Add(cell);
}
}
// And finally, add the TableRow to the Table
tblArtikels.Rows.Add(row);
}
//Sore the current Rows Count in ViewState
numOfRows = rowsCount;
}
catch (Exception ex)
{
huidigDocument.log("DocumentToevoegen.aspx", "Genereer tabel", ex.Message.ToString());
}
}
Below the .cs file i'm using to get the list items from SharePoint =>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Client;
namespace AdminCareWeb
{
public class Klanten
{
SharePointContextToken contextToken;
string accessToken;
string currentUser;
Uri sharepointUrl;
string contextTokenString;
Document logging = new Document();
#region props
public string KlantID { get; set; }
public string KlantNaam { get; set; }
public string KlantAdres { get; set; }
public string KlantAdres2 { get; set; }
public string KlantPostcode { get; set; }
public string KlantPlaats { get; set; }
public string KlantLand { get; set; }
public string KlantOndernemingsnummerVoorloopcode { get; set; }
public string KlantOndernemingsnummer { get; set; }
#endregion
//Lijst maken van alle landen uit de SharePoint lijst landen.
public Dictionary<string, string> Landen()
{
Dictionary<string, string> landenLijst = new Dictionary<string, string>();
try
{
contextToken = PassThrough.contextToken;
sharepointUrl = PassThrough.sharepointUrl;
accessToken = PassThrough.accessToken;
ClientContext clientContext = TokenHelper.GetClientContextWithAccessToken(sharepointUrl.ToString(), accessToken);
// Lijst met Landen ophalen en dropdown vullen
List oListLanden = clientContext.Web.Lists.GetByTitle("Lijst landen");
clientContext.ExecuteQuery();
CamlQuery cQLand = new CamlQuery();
cQLand.ViewXml = "<View><Query></Query></View>";
Microsoft.SharePoint.Client.ListItemCollection landListItem = oListLanden.GetItems(cQLand);
clientContext.Load(landListItem, items => items.Include(
item => item["ID"],
item => item["LDnaam"]));
clientContext.ExecuteQuery();
foreach (Microsoft.SharePoint.Client.ListItem landItem in landListItem)
{
string ID = landItem["ID"].ToString();
string landNaam = landItem["LDnaam"].ToString();
landenLijst.Add(ID, landNaam);
}
}
catch (Exception ex)
{
logging.log("Klanten.cs", "Landen ophalen", ex.Message.ToString());
}
return landenLijst;
}
//Lijst maken van alle postcodes uit de SharePoint lijst postcodes en gemeentes.
public Dictionary<string, string> Postcodes()
{
Dictionary<string, string> postcodesLijst = new Dictionary<string, string>();
try
{
contextToken = PassThrough.contextToken;
sharepointUrl = PassThrough.sharepointUrl;
accessToken = PassThrough.accessToken;
ClientContext clientContext = TokenHelper.GetClientContextWithAccessToken(sharepointUrl.ToString(), accessToken);
//Lijst met postcodes ophalen en dropdown opvullen
List oListPostcodes = clientContext.Web.Lists.GetByTitle("Lijst postcodes");
clientContext.ExecuteQuery();
CamlQuery cQPostcodes = new CamlQuery();
cQPostcodes.ViewXml = "<View>"
+ "<Query>"
+ "<OrderBy><FieldRef Name='PCgemeente'/></OrderBy>"
+ "</Query>"
+ "</View>";
//Lijst aanmaken met het resultaat van de uitgevoerde query.
Microsoft.SharePoint.Client.ListItemCollection postcodeListItem = oListPostcodes.GetItems(cQPostcodes);
clientContext.Load(postcodeListItem, items => items.Include(
item => item["ID"],
item => item["PCgemeente"]));
clientContext.ExecuteQuery();
foreach (Microsoft.SharePoint.Client.ListItem postcodeItem in postcodeListItem)
{
string ID = postcodeItem["ID"].ToString();
string gemeente = postcodeItem["PCgemeente"].ToString();
postcodesLijst.Add(ID, gemeente);
}
}
catch (Exception ex)
{
logging.log("Klanten.cs", "Postcodes ophalen", ex.Message.ToString());
}
return postcodesLijst;
}
//Lijst maken van alle landen uit de SharePoint lijst landen.
public Dictionary<string, string> KlantenOphalen()
{
Dictionary<string, string> klantenLijst = new Dictionary<string, string>();
try
{
contextToken = PassThrough.contextToken;
sharepointUrl = PassThrough.sharepointUrl;
accessToken = PassThrough.accessToken;
ClientContext clientContext = TokenHelper.GetClientContextWithAccessToken(sharepointUrl.ToString(), accessToken);
// Lijst met Landen ophalen en dropdown vullen
List oListKLanten = clientContext.Web.Lists.GetByTitle("Lijst Relaties");
clientContext.ExecuteQuery();
CamlQuery cQKlant = new CamlQuery();
cQKlant.ViewXml = "<View>"
+ "<Query>"
+ "<Where><Eq><FieldRef Name='RLtyperelatie' /><Value Type='Choice'>Klant</Value></Eq></Where>"
+ "<OrderBy><FieldRef Name='RLnaam'/></OrderBy>"
+ "</Query>"
+ "</View>";
Microsoft.SharePoint.Client.ListItemCollection klantListItem = oListKLanten.GetItems(cQKlant);
clientContext.Load(klantListItem, items => items.Include(
item => item["RLnaam"]));
clientContext.ExecuteQuery();
foreach (Microsoft.SharePoint.Client.ListItem klantItem in klantListItem)
{
string klantNaam = klantItem["RLnaam"].ToString();
klantenLijst.Add(klantNaam, klantNaam);
}
}
catch (Exception ex)
{
logging.log("Klanten.cs", "Klanten ophalen", ex.Message.ToString());
}
return klantenLijst;
}
}
}
Anyone have some suggestions to speed up. Well the problem is now it takes 7 -8 seconds before the page is showing up. Postbacks takes 3-5 seconds.
I am trying to add a rows to a RadGridView when a use click a button on the form (ie. "Add".)
When the form load I add columns to the RadGridView and make all of them all ReadOnly except one .
When a user click the "Add" button, I want to add a row to this RadGridView. Basically, a user types a UPC code, then I read data from the database and add new row in a grid view with the item name, item price.
Here is what I did to create the columns
private void Register_Load(object sender, EventArgs e) {
GridViewTextBoxColumn UPC = new GridViewTextBoxColumn();
UPC.Name = "UPC";
UPC.HeaderText = "UPC";
UPC.FieldName = "UPC";
UPC.MaxLength = 50;
UPC.TextAlignment = ContentAlignment.BottomRight;
radGridView1.MasterTemplate.Columns.Add(UPC);
radGridView1.Columns["UPC"].Width = 120;
radGridView1.Columns["UPC"].ReadOnly = true;
GridViewTextBoxColumn ItemName = new GridViewTextBoxColumn();
ItemName.Name = "Item Name";
ItemName.HeaderText = "Item Name";
ItemName.FieldName = "ItemName";
ItemName.MaxLength = 100;
ItemName.TextAlignment = ContentAlignment.BottomRight;
radGridView1.MasterTemplate.Columns.Add(ItemName);
radGridView1.Columns["Item Name"].Width = 210;
radGridView1.Columns["Item Name"].ReadOnly = true;
GridViewDecimalColumn QtyColumn = new GridViewDecimalColumn();
QtyColumn.Name = "Qty";
QtyColumn.HeaderText = "Quantity";
QtyColumn.FieldName = "Qty";
QtyColumn.DecimalPlaces = 1;
radGridView1.MasterTemplate.Columns.Add(QtyColumn);
radGridView1.Columns["Qty"].Width = 75;
GridViewMaskBoxColumn PriceColumn = new GridViewMaskBoxColumn();
PriceColumn.Name = "Unit Price";
PriceColumn.FieldName = "UnitPrice";
PriceColumn.HeaderText = "Unit Price";
PriceColumn.MaskType = MaskType.Numeric;
PriceColumn.Mask = "C";
PriceColumn.TextAlignment = ContentAlignment.BottomRight;
PriceColumn.FormatString = "{0:C}";
PriceColumn.DataType = typeof(decimal);
radGridView1.MasterTemplate.Columns.Add(PriceColumn);
radGridView1.Columns["Unit Price"].Width = 75;
radGridView1.Columns["Unit Price"].ReadOnly = true;
GridViewMaskBoxColumn TotalColumn = new GridViewMaskBoxColumn();
TotalColumn.Name = "Total Price";
TotalColumn.FieldName = "TotalPrice";
TotalColumn.HeaderText = "Total Price";
TotalColumn.MaskType = MaskType.Numeric;
TotalColumn.Mask = "C";
TotalColumn.TextAlignment = ContentAlignment.BottomRight;
TotalColumn.FormatString = "{0:C}";
TotalColumn.DataType = typeof(decimal);
radGridView1.MasterTemplate.Columns.Add(TotalColumn);
radGridView1.Columns["Total Price"].Width = 75;
radGridView1.Columns["Total Price"].ReadOnly = true;
}
To add the row Here is what I am doing "when a user click the 'Add' button)
private void ButtonAdd_Click(object sender, EventArgs e) {
string UPC = InputUPC.Text.Trim();
if (UPC.Length < 3) {
return;
}
string sql = " SELECT p.productName, p.price "
+ " FROM products AS p "
+ " WHERE p.productUPC = #upc ";
var parms = new List<MySqlParameter>();
parms.Add(new MySqlParameter("#upc", UPC));
var db = new dbConnetion();
foreach (var i in db.getData(sql, parms, r =>
new ProductsTable() {
_productName = r["productName"].ToString(),
_price = Convert.ToDouble(r["price"])
}
)
) {
//radGridView1.Rows[0].Cells[0].Value = 4.3;
radGridView1.Rows[0].Cells["UPC"].Value = UPC;
radGridView1.Rows[0].Cells["Item Name"].Value = i._productName;
radGridView1.Rows[0].Cells["Qty"].Value = "1";
radGridView1.Rows[0].Cells["Unit Price"].Value = i._price;
radGridView1.Rows[0].Cells["Total Price"].Value = (Convert.ToDouble(i._price) * Convert.ToInt32(radGridView1.Rows[0].Cells["Qty"].Value)).ToString();
}
}
But the add row is giving me an error
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
How can I correctly add rows to the RadGridView when the "Add" button is clicked.
ButtonAdd_Click is wrong because the foreach is always trying to set row 0, which doesn't exist.
You don't specify what GridView you are using, so I can't give specifics, but typically you should be able to call Rows.Add(...).
I have to dynamically create controls and add them to a table. In a button click I need to find the value entered for that control. The control ids are also dynamic. Below is the code I tried.
private void createUdfControls()
{
colUdfNames.Clear();//this is a collection object.
//the from id for gl is 3.
colUdfNames = BL_GeneralLedger.GetAllUdfNames(3);
if (colUdfNames.Count>0)
{
TableRow tr1 = null; ;
for(int i=0;i<colUdfNames.Count;i++)
{
TableRow tr;
if(i%2==0)
{
tr = new TableRow();
tr1 = tr;
}
string udfTypeValue = colUdfNames[i].UdfTypeValue;
int EnumUdfTypeId = colUdfNames[i].Enum_UdfTypeId;
TableCell cellUdf1 = new TableCell();
TableCell cellUdfValue1 = new TableCell();
TableCell cellUdf2 = new TableCell();
TableCell cellUdfValue2 = new TableCell();
switch (EnumUdfTypeId)
{
case 1:
{
//Text
if (i % 2 == 0)
{
cellUdf1.Text = colUdfNames[i].UdfName;
TextBox txtText = new TextBox();
txtText.ID = "txtText" + colUdfNames[i].UdfId;
txtText.MaxLength = colUdfNames[i].Width;
txtText.Text = "ww";
cellUdfValue1.Controls.Add(txtText);
}
else
{
cellUdf2.Text = colUdfNames[i].UdfName;
TextBox txtText = new TextBox();
txtText.ID = "txtText" + colUdfNames[i].UdfId;
txtText.MaxLength = colUdfNames[i].Width;
txtText.Text = "ww";
cellUdfValue2.Controls.Add(txtText);
}
break;
}
case 2:
{
//Number
if(i%2==0)
{
cellUdf1.Text = colUdfNames[i].UdfName;
TextBox txtNumber = new TextBox();
txtNumber.ID = "txtNumber" + colUdfNames[i].UdfId;
txtNumber.MaxLength = colUdfNames[i].Width;
txtNumber.Text = "12";
cellUdfValue1.Controls.Add(txtNumber);
DataRow dr = dtUdfControlInfo.NewRow();
dr[0] = txtNumber.ID;
dtUdfControlInfo.Rows.Add(dr);
}
else
{
cellUdf2.Text = colUdfNames[i].UdfName;
TextBox txtNumber = new TextBox();
txtNumber.ID = "txtNumber" + colUdfNames[i].UdfId;
txtNumber.MaxLength = colUdfNames[i].Width;
txtNumber.Text = "12";
cellUdfValue2.Controls.Add(txtNumber);
DataRow dr = dtUdfControlInfo.NewRow();
dr[0] = txtNumber.ID;
dtUdfControlInfo.Rows.Add(dr);
}
break;
}
case 3:
{
//Decimal
if(i%2==0)
{
cellUdf1.Text = colUdfNames[i].UdfName;
TextBox txtDecimal = new TextBox();
txtDecimal.ID = "txtDecimal" + colUdfNames[i].UdfId;
txtDecimal.MaxLength = colUdfNames[i].Width;
txtDecimal.Text = "2.2";
cellUdfValue1.Controls.Add(txtDecimal);
}
else
{
cellUdf2.Text = colUdfNames[i].UdfName;
TextBox txtDecimal = new TextBox();
txtDecimal.ID = "txtDecimal" + colUdfNames[i].UdfId;
txtDecimal.MaxLength = colUdfNames[i].Width;
txtDecimal.Text = "2.2";
cellUdfValue2.Controls.Add(txtDecimal);
}
break;
}
case 4:
{
//Memo
if(i%2==0)
{
cellUdf1.Text = colUdfNames[i].UdfName;
TextBox txtMemo = new TextBox();
txtMemo.TextMode = TextBoxMode.MultiLine;
txtMemo.ID = "txtMemo" + colUdfNames[i].UdfId;
txtMemo.MaxLength = colUdfNames[i].Width;
txtMemo.Text = "memo";
cellUdfValue1.Controls.Add(txtMemo);
DataRow dr = dtUdfControlInfo.NewRow();
dr[0] = txtMemo.ID;
dtUdfControlInfo.Rows.Add(dr);
}
else
{
cellUdf2.Text = colUdfNames[i].UdfName;
TextBox txtMemo = new TextBox();
txtMemo.TextMode = TextBoxMode.MultiLine;
txtMemo.ID = "txtMemo" + colUdfNames[i].UdfId;
txtMemo.MaxLength = colUdfNames[i].Width;
txtMemo.Text = "memo";
cellUdfValue2.Controls.Add(txtMemo);
DataRow dr = dtUdfControlInfo.NewRow();
dr[0] = txtMemo.ID;
dtUdfControlInfo.Rows.Add(dr);
}
break;
}
case 5:
{
//date
if(i%2==0)
{
cellUdf1.Text = colUdfNames[i].UdfName;
TextBox txtDate = new TextBox();
txtDate.ID = "txtDate" + colUdfNames[i].UdfId;
txtDate.MaxLength = colUdfNames[i].Width;
txtDate.Text = "12.07.2010";
cellUdfValue1.Controls.Add(txtDate);
}
else
{
cellUdf2.Text = colUdfNames[i].UdfName;
TextBox txtDate = new TextBox();
txtDate.ID = "txtDate" + colUdfNames[i].UdfId;
txtDate.MaxLength = colUdfNames[i].Width;
txtDate.Text = "12.07.2010";
cellUdfValue2.Controls.Add(txtDate);
}
break;
}
case 6:
{
//Datetime
if(i%2==0)
{
cellUdf1.Text = colUdfNames[i].UdfName;
TextBox txtDateTime = new TextBox();
txtDateTime.ID = "txtDateTime" + colUdfNames[i].UdfId;
txtDateTime.MaxLength = colUdfNames[i].Width;
txtDateTime.Text = "12.07.2010";
cellUdfValue1.Controls.Add(txtDateTime);
}
else
{
cellUdf2.Text = colUdfNames[i].UdfName;
TextBox txtDateTime = new TextBox();
txtDateTime.ID = "txtDateTime" + colUdfNames[i].UdfId;
txtDateTime.MaxLength = colUdfNames[i].Width;
txtDateTime.Text = "12.07.2010";
cellUdfValue2.Controls.Add(txtDateTime);
}
break;
}
case 7:
{
//"Dropdown"
if(i%2==0)
{
cellUdf1.Text = colUdfNames[i].UdfName;
DropDownList ddlDropDown = new DropDownList();
ddlDropDown.ID = "ddlDropDown" + colUdfNames[i].UdfId;
cellUdfValue1.Controls.Add(ddlDropDown);
LoadUdfList(ddlDropDown, colUdfNames[i].UdfId);
if (colUdfNames[i].IsMandatory)
{
ddlDropDown.Items.Insert(0, new ListItem("Select " + colUdfNames[i].UdfName, "0", true));
}
}
else
{
cellUdf2.Text = colUdfNames[i].UdfName;
DropDownList ddlDropDown = new DropDownList();
ddlDropDown.ID = "ddlDropDown" + colUdfNames[i].UdfId;
cellUdfValue2.Controls.Add(ddlDropDown);
LoadUdfList(ddlDropDown, colUdfNames[i].UdfId);
if (colUdfNames[i].IsMandatory)
{
ddlDropDown.Items.Insert(0, new ListItem("Select " + colUdfNames[i].UdfName, "0", true));
}
}
break;
}
case 8:
{
//"Checkbox"
if(i%2==0)
{
cellUdf1.Text = colUdfNames[i].UdfName;
CheckBox ChkBox = new CheckBox();
ChkBox.ID = "ChkBox" + colUdfNames[i].UdfId;
ChkBox.Checked = true;
cellUdfValue1.Controls.Add(ChkBox);
}
else
{
cellUdf2.Text = colUdfNames[i].UdfName;
CheckBox ChkBox = new CheckBox();
ChkBox.ID = "ChkBox" + colUdfNames[i].UdfId;
ChkBox.Checked = true;
cellUdfValue2.Controls.Add(ChkBox);
}
break;
}
}
if (i % 2 == 0)
{
tr1.Cells.AddAt(0, cellUdf1);
tr1.Cells.AddAt(1, cellUdfValue1);
}
else
{
tr1.Cells.AddAt(2, cellUdf2);
tr1.Cells.AddAt(3, cellUdfValue2);
}
tblUdf.Rows.Add(tr1);
// tblUdf.DataBind();
}
}
}
and the read function as below
private void readValuesFromUdfControls()
{
colUdfDataMaster.Clear();
int c= tblUdf.Controls.Count;
int tablrow= tblUdf.Rows.Count;
//TextBox tb1 = (TextBox)tblUdf.Rows[0].FindControl(dtUdfControlInfo.Rows[0][0].ToString());
//string tb1 = (string)Request.Form["ctl00_ContentPlaceHolder1_" + dtUdfControlInfo.Rows[0][0].ToString()];
for (int j = 0; j < tblUdf.Rows.Count;j++ )
{
for (int k = 0; k < tblUdf.Rows[j].Cells.Count;k++ )
{
Control ctrl = tblUdf.Rows[j].Cells[k].Controls[1];
for (int i = 0; i < colUdfNames.Count; i++)
{
PL_UdfDataMaster objUdfDataMaster = new PL_UdfDataMaster();
if (ctrl.ID.Contains("txtText"))
{
TextBox tb = (TextBox)ctrl;
objUdfDataMaster.UdfId = colUdfNames[i].UdfId;
objUdfDataMaster.MasterId = ErpSessions._GeneralLedgerId;
objUdfDataMaster.Enum_FormId = 3;
objUdfDataMaster.UdfData = tb.Text;
}
else if (ctrl.ID.Contains("txtNumber"))
{
TextBox tb = (TextBox)ctrl;
objUdfDataMaster.UdfId = colUdfNames[i].UdfId;
objUdfDataMaster.MasterId = ErpSessions._GeneralLedgerId;
objUdfDataMaster.Enum_FormId = 3;
objUdfDataMaster.UdfData = tb.Text;
}
else if (ctrl.ID.Contains("txtDecimal"))
{
TextBox tb = (TextBox)ctrl;
objUdfDataMaster.UdfId = colUdfNames[i].UdfId;
objUdfDataMaster.MasterId = ErpSessions._GeneralLedgerId;
objUdfDataMaster.Enum_FormId = 3;
objUdfDataMaster.UdfData = tb.Text;
}
else if (ctrl.ID.Contains("txtMemo"))
{
TextBox tb = (TextBox)ctrl;
objUdfDataMaster.UdfId = colUdfNames[i].UdfId;
objUdfDataMaster.MasterId = ErpSessions._GeneralLedgerId;
objUdfDataMaster.Enum_FormId = 3;
objUdfDataMaster.UdfData = tb.Text;
}
else if (ctrl.ID.Contains("txtDate"))
{
TextBox tb = (TextBox)ctrl;
objUdfDataMaster.UdfId = colUdfNames[i].UdfId;
objUdfDataMaster.MasterId = ErpSessions._GeneralLedgerId;
objUdfDataMaster.Enum_FormId = 3;
objUdfDataMaster.UdfData = tb.Text;
}
else if (ctrl.ID.Contains("txtDateTime"))
{
TextBox tb = (TextBox)ctrl;
objUdfDataMaster.UdfId = colUdfNames[i].UdfId;
objUdfDataMaster.MasterId = ErpSessions._GeneralLedgerId;
objUdfDataMaster.Enum_FormId = 3;
objUdfDataMaster.UdfData = tb.Text;
}
else if (ctrl.ID.Contains("ddlDropDown"))
{
DropDownList ddl = (DropDownList)ctrl;
objUdfDataMaster.UdfId = colUdfNames[i].UdfId;
objUdfDataMaster.MasterId = ErpSessions._GeneralLedgerId;
objUdfDataMaster.Enum_FormId = 3;
objUdfDataMaster.UdfData = ddl.SelectedItem.Text;
}
else if (ctrl.ID.Contains("ChkBox"))
{
CheckBox chk = (CheckBox)ctrl;
objUdfDataMaster.UdfId = colUdfNames[i].UdfId;
objUdfDataMaster.MasterId = ErpSessions._GeneralLedgerId;
objUdfDataMaster.Enum_FormId = 3;
objUdfDataMaster.UdfData = chk.Checked == true ? "true" : "false";
}
colUdfDataMaster.Add(objUdfDataMaster);
}
}
}
}
the problem is that i m getting the rowcount=0 of the table tblUdf inside which i added the table rows and controls inside the table cells.
Any help how to get the control values of the dynamically added controls.
Thankx.
Mohak
You need to make sure that you add the controls again on postback before you read back the values.
To elaborate on Ben's answer, you need to override the CreateChildControls method and create your controls there. The docs for this method provide a handy example of doing what you're doing:
http://msdn.microsoft.com/en-us/library/system.web.ui.control.createchildcontrols.aspx