Getting values of my childRepeater - asp.net

I have 2 repeaters where the first one list the questions and the second one list multiple choice for that specific question.
However, there are some multiple choice(input type="radio") or Text(input type="text") anwers. Im trying to get the value of either one(radio) or the other(text).
<%# DataBinder.Eval(Container.DataItem,"Descricao")%>
<%-- Listagem de Respostas --%>
<asp:Repeater ID="uxRespList" runat="server" OnItemDataBound="uxRespList_ItemDataBound" OnItemCommand="uxRespList_ItemCommand">
<ItemTemplate>
<tr>
<td>
<div id="uxRespostaText" visible="false" runat="server">
<input type="text" id="uxRespostaDissertativa" placeholder="Resposta" style="width:1000px" ></input>
</div>
<div id="uxRespostaRadio" visible="false" runat="server">
<input type="radio" id="uxResposta" runat="server" value='<%# DataBinder.Eval(Container.DataItem, "Descricao")%>'/><%# DataBinder.Eval(Container.DataItem, "Descricao")%>
</div>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:Repeater>
Code Behind
protected void uxQuestList_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Repeater rptRespostas = (Repeater)(e.Item.FindControl("uxRespList"));
QuestionarioPergunta pergunta = (QuestionarioPergunta)e.Item.DataItem;
rptRespostas.DataSource = ctx.QuestionarioRespostas.Where(x => x.PergId == pergunta.Id).ToList();
PergId.Text = pergunta.Id.ToString();
rptRespostas.DataBind();
}
}
protected void uxRespList_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
System.Web.UI.HtmlControls.HtmlContainerControl uxRespostaText = (System.Web.UI.HtmlControls.HtmlContainerControl)e.Item.FindControl("uxRespostaText");
System.Web.UI.HtmlControls.HtmlContainerControl uxRespostaRadio = (System.Web.UI.HtmlControls.HtmlContainerControl)e.Item.FindControl("uxRespostaRadio");
int PerguntaID = Int32.Parse(PergId.Text);
var pergunta = ctx.QuestionarioPerguntas.Where(x => x.Id == PerguntaID).FirstOrDefault();
if (pergunta.TipoPergunta == "Dissertativa")
{
uxRespostaText.Visible = true;
}
else
{
uxRespostaRadio.Visible = true;
}
}
}
//Save here
protected void uxSalvarPesquisa_Click(object sender, EventArgs e)
{
foreach (RepeaterItem item in uxRespList.Items)
{
}
}

You can get values of your html input as below and based on your requirement you can modify the code.
foreach (RepeaterItem item in uxQuestList.Items)
{
Repeater uxRespList = (Repeater)item.FindControl("uxRespList");
foreach (RepeaterItem inneritem in uxRespList.Items)
{
HtmlInputText input = (HtmlInputText)inneritem.FindControl("uxRespostaDissertativa");
if (input.Attributes["visible"] == "true")
{
var answer = input.Value;
}
HtmlInputRadioButton inputRadio = (HtmlInputRadioButton)inneritem.FindControl("uxRespostaRadio");
if (inputRadio.Attributes["visible"] == "true")
{
var answer = inputRadio.Value;
}
}
}

Related

How enable and disable button in DevExpress

I develop an application with DevExpress, but I have a problem in my code, I want a condition for my button "save", if condition "A" button save enable, but if condition "B" button save disable,but in my code the button "save" enable in the 2 cases.
how to fix this problem?
<% if (Condition == A )
{
%>
<td>
<dx:ASPxButton ID="BtSavelisteningScale" runat="server" HorizontalAlign="NotSet"
ImagePosition="Left" Text="Enregistrer" VerticalAlign="NotSet" ClientEnabled="true" ClientInstanceName="BtSavelisteningScale"
Wrap="Default" AutoPostBack="false" meta:resourcekey="BtSavelisteningScaleResource1">
<ClientSideEvents Click="function(s, e){if (ASPxClientEdit.ValidateGroup('grpVal')) {CPlEvalScale.PerformCallback('Enregistrer');} }" />
<%--<ClientSideEvents Click="function(s, e){ if (ASPxClientEdit.ValidateGroup('grpVal')) {GetScore();GvLs.PerformCallback('UpdateListenningScale');}}" />--%>
</dx:ASPxButton>
</td>
<% } %>
<% else if (Condition == B )
{
%>
<td>
<dx:ASPxButton ID="BtSavelisteningScaleFalse" runat="server" HorizontalAlign="NotSet"
ImagePosition="Left" Text="Enregistrer" VerticalAlign="NotSet" ClientEnabled="false" ClientInstanceName="BtSavelisteningScale"
Wrap="Default" AutoPostBack="false" meta:resourcekey="BtSavelisteningScaleResource1">
<ClientSideEvents Click="function(s, e){if (ASPxClientEdit.ValidateGroup('grpVal')) {CPlEvalScale.PerformCallback('Enregistrer');} }" />
<%--<ClientSideEvents Click="function(s, e){ if (ASPxClientEdit.ValidateGroup('grpVal')) {GetScore();GvLs.PerformCallback('UpdateListenningScale');}}" />--%>
</dx:ASPxButton>
</td>
<% } %>
By Default Set it Visiable = False Then
Page_Load Event or Page_Init Event Check your condition. example:
protected void Page_Load(object sender, EventArgs e)
{
if (Condition == A)
{
BtSavelisteningScale.Visiable = True;
BtSavelisteningScaleFalse.Visiable = False;
}
else if (Condition == B)
{
BtSavelisteningScale.Visiable = False;
BtSavelisteningScaleFalse.Visiable = True;
}
}
Protected void Page_init(object sender, EventArgs e)
{
if (Condition == A)
{
BtSavelisteningScale.Visiable = True;
BtSavelisteningScaleFalse.Visiable = False;
}
else if (Condition == B)
{
BtSavelisteningScale.Visiable = False;
BtSavelisteningScaleFalse.Visiable = True;
}
}

RadGrid: Get the modified Items on edit

On a RadGrid I can use the CommandItemTemplate to define my own buttons for, in my case, Save and Cancel the edit (like below)
<CommandItemTemplate>
<div style="padding: 5px 5px;">
<asp:LinkButton ID="btnUpdateEdited" runat="server" CommandName="UpdateEdited">Update</asp:LinkButton>
<asp:LinkButton ID="btnCancel" runat="server" CommandName="CancelAll">Cancel editing</asp:LinkButton>
</div>
</CommandItemTemplate>
On the code behind, I set up the ItemCommand.
> protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
if (e.CommandName.CompareTo("UpdateEdited") == 0)
{
var commandItem = ((GridCommandItem)e.Item);
//Updade code here.
}
}
How can I access the modified row with the modified fields so I can perform an updade?
You should have them in command item and you can access them like this:
GridDataItem item = (GridDataItem)e.Item;
string value = item["ColumnUniqueName"].Text;
Is this what you want ? Just a sample you might need to modify it..
.aspx
<telerik:RadGrid ID="rg" runat="server" AutoGenerateColumns="false"
OnNeedDataSource="rg_NeedDataSource" OnItemCommand="rg_ItemCommand"
MasterTableView-CommandItemDisplay="Top" OnItemDataBound="rg_ItemDataBound">
<MasterTableView EditMode="InPlace">
<CommandItemTemplate>
<div style="padding: 5px 5px;">
<asp:LinkButton ID="btnUpdateEdited" runat="server"
CommandName="UpdateEdited">Update</asp:LinkButton>
<asp:LinkButton ID="btnCancel" runat="server"
CommandName="CancelAll">Cancel editing</asp:LinkButton>
</div>
</CommandItemTemplate>
<Columns>
<telerik:GridTemplateColumn>
<ItemTemplate>
<asp:Label ID="lbl" runat="server"
Text='<%# Eval("A") %>' />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txt" runat="server"
Text='<%# Eval("A") %>'></asp:TextBox>
</EditItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn>
<ItemTemplate>
<asp:LinkButton ID="btnEdit" runat="server" Text="Edit"
CommandName="Edit"></asp:LinkButton>
</ItemTemplate>
<EditItemTemplate> </EditItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
</MasterTableView>
</telerik:RadGrid>
.cs
protected void Page_Load(object sender, EventArgs e)
{
// Check
if (!IsPostBack)
{
// Variable
DataTable dt = new DataTable();
dt.Columns.Add("A");
dt.Rows.Add("A1");
// Check & Bind
if (dt != null)
{
// Viewstate
ViewState["Data"] = dt;
rg.DataSource = dt;
rg.DataBind();
dt.Dispose();
}
}
}
protected void rg_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
rg.DataSource = ViewState["Data"] as DataTable;
}
protected void rg_ItemCommand(object sender, GridCommandEventArgs e)
{
// Check
if (e.CommandName == "UpdateEdited")
{
// Variable
DataTable dt = new DataTable();
dt.Columns.Add("A");
// Loop All
foreach (GridEditableItem item in rg.Items)
{
// Find Control
TextBox txt = item.FindControl("txt") as TextBox;
// Check & Add to DataTable
if (txt != null) dt.Rows.Add(txt.Text.Trim());
}
// Check
if (dt != null && dt.Rows.Count > 0)
{
// Set Viewstate
ViewState["Data"] = dt;
// Bind
rg.DataSource = dt;
rg.DataBind();
// Dispose
dt.Dispose();
}
}
else if (e.CommandName == "CancelAll")
{
// Clear Edit Mode
rg.MasterTableView.ClearChildEditItems();
// Rebind
rg.Rebind();
}
}
protected void rg_ItemDataBound(object sender, GridItemEventArgs e)
{
// Check
if (e.Item is GridCommandItem)
{
// Find Control
LinkButton btnUpdateEdited = e.Item.FindControl("btnUpdateEdited") as LinkButton;
LinkButton btnCancel = e.Item.FindControl("btnCancel") as LinkButton;
// Get is Edit Mode ?
if (rg.EditIndexes.Count > 0)
{
if (btnUpdateEdited != null) btnUpdateEdited.Visible = true;
if (btnCancel != null) btnCancel.Visible = true;
}
else
{
if (btnUpdateEdited != null) btnUpdateEdited.Visible = false;
if (btnCancel != null) btnCancel.Visible = false;
}
}
}

Getting values from textbox in the repeater in button click event

I have a TextBox in a repeater that is populated from the database in the ItemDataBound event. When I tried to get the text inside the TextBox in a Button_Click event I found the TextBox.Text empty. How can I get the Text?
foreach (RepeaterItem repeated in repEdit.Items)
{
DropDownList drp = (DropDownList)FindControlRecursive(repeated, "drpdown");
TextBox txt = (TextBox)FindControlRecursive(repeated, "txt");
CheckBox chk = (CheckBox)FindControlRecursive(repeated, "chk");
if (drp != null && !string.IsNullOrEmpty(drp.Attributes["ID"]))
{
loc.GetType().GetProperty(drp.Attributes["ID"].Split('#')[0] + "ID").SetValue(loc, int.Parse(drp.SelectedValue), null);
}
if (txt != null && !string.IsNullOrEmpty(txt.Attributes["ID"]))
{
if (txt.Attributes["ID"].Contains("#int"))
{
loc.GetType().GetProperty(txt.Attributes["ID"].Split('#')[0]).SetValue(loc, int.Parse(txt.Text), null);
}
else if (txt.Attributes["ID"].Contains("#decimal"))
{
loc.GetType().GetProperty(txt.Attributes["ID"].Split('#')[0]).SetValue(loc, decimal.Parse(txt.Text), null);
}
else
{
loc.GetType().GetProperty(txt.Attributes["ID"].Split('#')[0]).SetValue(loc, txt.Text, null);
}
}
if (chk!=null && !string.IsNullOrEmpty(chk.Attributes["ID"]))
{
loc.GetType().GetProperty(chk.Attributes["ID"].Split('#')[0]).SetValue(loc, chk.Checked, null);
}
}
HTML
<asp:Repeater ID="repEdit" runat="server" OnItemDataBound="repEdit_ItemDataBound">
<ItemTemplate>
<asp:Label ID="lblName" runat="server" Visible="false"></asp:Label>
<asp:TextBox ID="txt" runat="server" Visible="false"></asp:TextBox>
<asp:CheckBox ID="chk" runat="server" Visible="false" />
<asp:DropDownList ID="drpdown" runat="server" Visible="false">
</asp:DropDownList>
<br />
</ItemTemplate>
</asp:Repeater>
Here is the itemdatabound event
protected void repEdit_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
Label name = e.Item.FindControl("lblName") as Label;
TextBox text = e.Item.FindControl("txt") as TextBox;
CheckBox chk = e.Item.FindControl("chk") as CheckBox;
DropDownList drp = e.Item.FindControl("drpdown") as DropDownList;
Button but = e.Item.FindControl("butEdit") as Button;
//butEdit.Visible = true;
if (but != null)
{
but.Visible = true;
}
if (e.Item.ItemType == ListItemType.Item)
{
KeyValuePair<string, Dictionary<int, string>> kvp = (KeyValuePair<string, Dictionary<int, string>>)e.Item.DataItem;
if (name != null)
{
if (kvp.Key.Contains("#datetime"))
{
return;
}
name.Visible = true;
name.Text = kvp.Key.Split('#')[0].ToString();
}
if (kvp.Key.Contains("#int") || kvp.Key.Contains("#decimal"))
{
text.Visible = true;
text.ID = kvp.Key;
text.EnableViewState = true;
text.Attributes["ID"] = kvp.Key;
text.Text = kvp.Value[0].ToString();
if (kvp.Key.Split('#')[0] == "ID")
{
text.Enabled = false;
}
}
Here is your Repeater. It has a PlaceHolder and Button.
<asp:Repeater ID="rpNotifications" runat="server"
OnItemDataBound="rpNotifications_ItemDataBound">
<ItemTemplate>
<asp:PlaceHolder ID="commentHolder" runat="server"></asp:PlaceHolder>
<asp:Button runat="server" ID="btnComment"
Text="Comment" CssClass="btn blue"
OnClick="btnComment_Click" CommandArgument='<%# Eval("id") %>' />
</ItemTemplate>
</asp:Repeater>
The button has the command argument set as the Id of the data I am binding to it.
Next here is where you need to Bind your Repeater. If you don't Bind it in the Page_Init the resulting values in the dynamically created controls will be lost.
protected void Page_Init(object sender, EventArgs e)
{
rpNotifications.DataSource = {datasource-here}
rpNotifications.DataBind();
}
And here is why (Image from: http://msdn.microsoft.com/en-us/library/ms972976.aspx)
Dynamically Create Control on ItemDataBound
You will need to add the textbox to the placeholder as this is the only way to dynamically assign an ID to the control.
protected void rpNotifications_ItemDataBound(object sender,
RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item
|| e.Item.ItemType == ListItemType.AlternatingItem)
{
Common.Models.Item item = (Common.Models.Item)e.Item.DataItem;
// Create new Control
TextBox txtComment = new TextBox();
txtComment.ID = String.Format("txtComment{0}", item.id.ToString());
// Ensure static so you can reference it by Id
txtComment.ClientIDMode = System.Web.UI.ClientIDMode.Static;
// Add control to placeholder
e.Item.FindControl("commentHolder").Controls.Add(txtComment);
}
}
Get Value On Button Click
Now you need to create the event handler for the button and get the resulting value
protected void btnComment_Click(object sender, EventArgs e)
{
// This is the ID I put in the CommandArgument
Guid id = new Guid(((Button)sender).CommandArgument);
String comment = String.Empty;
// Loop through the repeaterItems to find your control
foreach (RepeaterItem item in rpNotifications.Controls)
{
Control ctl = item.FindControl(
String.Format("txtComment{0}", id.ToString()));
if (ctl != null)
{
comment = ((TextBox)ctl).Text;
break;
}
}
}
Try to get ASP.Net controls using below code
DropDownList drp = (DropDownList)repeated.FindControl("drpdown");
TextBox txt = (TextBox)repeated.FindControl("txt");
CheckBox chk = (CheckBox)repeated.FindControl("chk");
Then you can get values from there respective properties.

ASP.NET get all values of radiobuttonlist that in repeater?

aspx file:
<asp:Repeater ID="Repeater_sorular" runat="server">
<HeaderTemplate>
</HeaderTemplate>
<ItemTemplate>
<div class="div_soru">
<div class="div_soru_wrapper">
<%#Eval("Subject")%>
<asp:RadioButtonList ID="RadioButtonList_secenekler" runat="server" Visible='<%# Eval("TypeId").ToString() == "1" %>'
DataSource='<%#Eval("Secenekler")%>' DataTextField='<%#Eval("OptionName")%>' DataValueField='<%#Eval("OptionId")%>'>
</asp:RadioButtonList>
<asp:CheckBoxList ID="CheckBoxList_secenekler" runat="server" Visible='<%# Eval("TypeId").ToString() == "2" %>'
DataSource='<%#Eval("Secenekler")%>' DataTextField='<%#Eval("OptionName")%>' DataValueField='<%#Eval("OptionId")%>'>
</asp:CheckBoxList>
</div>
</div>
</ItemTemplate>
<FooterTemplate>
</FooterTemplate>
</asp:Repeater>
and codebehind:
SpAnketDataContext db = new SpAnketDataContext();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindRepeaterSorular();
}
}
protected void ImageButton_kaydet_OnCommand(object source, CommandEventArgs e)
{
}
private void BindRepeaterSorular()
{
int anket_id = 3;
var sorular = from soru in db.TableSurveyQuestions
where soru.SurveyId == anket_id
select new
{
soru.TypeId,
soru.Subject,
soru.QuestionId,
soru.SurveyId,
soru.QueueNo,
SurveyTitle = soru.TableSurvey.Title,
TypeName = soru.TableSurveyQuestionType.TypeName,
Secenekler = from secenekler in soru.TableSurveyOptions
select new
{
secenekler.OptionId,
secenekler.OptionName,
secenekler.QuestionId,
}
};
Repeater_sorular.DataSource = sorular;
Repeater_sorular.DataBind();
}
this is the code that I try to get values but I can get only last radiobuttonlist values.
protected void Repeater_sorular_ItemCommand(object sender, RepeaterCommandEventArgs e)
{
foreach (RepeaterItem item in Repeater_sorular.Items)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
CheckBoxList CheckBoxList1 = (CheckBoxList)e.Item.FindControl("CheckBoxList_secenekler");
RadioButtonList RadioButtonList1 = (RadioButtonList)e.Item.FindControl("RadioButtonList_secenekler");
if (CheckBoxList1 != null)
{
foreach (ListItem li in CheckBoxList1.Items)
{
TableSurveyVote votes=new TableSurveyVote();
votes.MemberId=1;
votes.OptionId=Int32.Parse(li.Value);
db.TableSurveyVotes.InsertOnSubmit(votes);
db.SubmitChanges();
}
}
if (RadioButtonList1 != null)
{
foreach (ListItem li in RadioButtonList1.Items)
{
TableSurveyVote votes=new TableSurveyVote();
votes.MemberId=1;
votes.OptionId=Int32.Parse(li.Value);
db.TableSurveyVotes.InsertOnSubmit(votes);
db.SubmitChanges();
}
}
}
}
}
What is wrong?
You get the same results as you say on the comment because you do not use the populate from the foreach loop (the item) but use the same reference e.Item on the loop.

Asp.Net set control that in specific row in repeater?

repeater code:
<asp:Repeater ID="Repeater_sorular" runat="server" OnItemCommand="Repeater_sorular_ItemCommand"
OnItemDataBound="Repeater_sorular_ItemBound">
<HeaderTemplate>
</HeaderTemplate>
<ItemTemplate>
<table>
<tr>
<td>
<rad:RadChart ID="RadChart1" runat="server" DefaultType="Pie" Width="700" >
<PlotArea Appearance-FillStyle-FillType="Gradient" Appearance-FillStyle-MainColor="#D90420"
Appearance-FillStyle-SecondColor="#FFAD4A" Appearance-Border-Visible="false">
<EmptySeriesMessage>
<TextBlock Text="Seçilen anket henüz oylanmamıştır.">
<Appearance TextProperties-Font="Tahoma, 10pt, style=Bold">
</Appearance>
</TextBlock>
</EmptySeriesMessage>
</PlotArea>
<ChartTitle>
<TextBlock Appearance-TextProperties-Font="Tahoma">
</TextBlock>
</ChartTitle>
<Appearance ImageQuality="HighQuality" Border-Color="#DFDDDD" TextQuality="ClearTypeGridFit">
</Appearance>
<Series>
<rad:ChartSeries Type="Pie" Appearance-TextAppearance-TextProperties-Color="#FFFFFF"
Appearance-TextAppearance-TextProperties-Font="Tahoma">
</rad:ChartSeries>
</Series>
<Legend Visible="True">
<TextBlock Visible="True">
</TextBlock>
</Legend>
</rad:RadChart>
</td>
<td>
<div style="font-weight: bolder; padding: 5px;">
<%#(((RepeaterItem)Container).ItemIndex+1).ToString() %>.
<%#Eval("Subject")%>
</div>
<asp:BulletedList ID="BulletedList_secenekler" runat="server" DataSource='<%#Eval("Secenekler")%>'
DataTextField="OptionName" DataValueField="OptionId" CssClass="sira_numarali">
</asp:BulletedList>
</td>
</tr>
</table>
</ItemTemplate>
<FooterTemplate>
</FooterTemplate>
</asp:Repeater>
repeater ItemDataBound:
protected void Repeater_sorular_ItemBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
int SurveyId = Int32.Parse(Request.QueryString["anket_id"]);
var sorular = from sr in db.TableSurveyQuestions
where sr.SurveyId == SurveyId
select sr;
//int repeater_satir = 0;
foreach (var soru in sorular)
{
RadChart RadChart1 = new RadChart();
RadChart1 = (RadChart)e.Item.FindControl("RadChart1");
ChartSeries s = RadChart1.Series.GetSeries(0);
s.Appearance.LegendDisplayMode = ChartSeriesLegendDisplayMode.ItemLabels;
s.Clear();
s.Appearance.ShowLabels = true;
s.Appearance.LabelAppearance.Dimensions.Margins.Bottom = 7;
s.PlotArea.IntelligentLabelsEnabled = true;
s.DataYColumn = "VoteCount";
int oy_sayisi = 0;
foreach (var secenek in soru.TableSurveyOptions)
{
int toplam_cevap_sayisi = secenek.TableSurveyVotes.Count;
int dogru_cevap_sayisi = secenek.TableSurveyVotes.Where(a => a.VoteStatus == true).Count();
double yuzde = ((double)dogru_cevap_sayisi / (double)toplam_cevap_sayisi) * 100;
ChartSeriesItem seriesItem = new ChartSeriesItem();
seriesItem.YValue = Math.Round(yuzde, 2);
seriesItem.Name = secenek.OptionName;
seriesItem.ActiveRegion.Tooltip = secenek.OptionName;
seriesItem.Label.TextBlock.Text = secenek.OptionName + " %" + Math.Round(yuzde, 2).ToString();
seriesItem.Appearance.Border.Color = Color.Silver;
seriesItem.Appearance.FillStyle.FillType = Telerik.Charting.Styles.FillType.Solid;
s.Items.Add(seriesItem);
RadChart1.Series.Add(s);
oy_sayisi = secenek.TableSurveyVotes.Count;
}
RadChart1.ChartTitle.TextBlock.Text = db.TableSurveyQuestions.Where(a => a.SurveyId == SurveyId).FirstOrDefault().TableSurvey.Title;
RadChart1.Legend.TextBlock.Text = "Toplam : " + oy_sayisi + " Oy ";
//repeater_satir++;
}
}
}
when I write this code, all charts are showing the last object values. I want to set each chart with different data.
How can I do this.
Thanks.
You could use the ItemIndex property
<asp:Repeater runat="server" ID="myRepeater" OnItemDataBound="myRepeater_ItemDataBound">
<ItemTemplate>
<asp:Label Text='<%# Eval("Id") %>' runat="server" ID="myRepeaterLabel" />
</ItemTemplate>
</asp:Repeater>
Code behind:
protected void myRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
switch (e.Item.ItemIndex)
{
case 3:
Label l = (Label)e.Item.FindControl("myRepeaterLabel");
l.Text += "whatever";
break;
default:
break;
}
}
}
Output:
Edited
I am not sure if this would help but you should bind your repeater like this:
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.BindRepeater();
}
}
private void BindRepeater()
{
var r = Builder<Product>.CreateListOfSize(20).Build();
this.myRepeater.DataSource = r;
this.myRepeater.DataBind();
}
And just modify specific values already bindded in the ItemDataBound event

Resources