In Visual Studio, I have a Repeater. This functions fine. It has checkboxes and labels. If someone checks the checkboxes in the Repeater, I want my button to be clicked and update my database based on what is and isn't checked.
My code currently selects ALL fields and updates ALL of them in the database (all rows get set to visible = 0). I want ONLY the CHECKED boxes to get Visible = 0. I need a WHERE statement that somehow sees only the checked fields, but I am at a loss of how to do this.
Here is my Repeater:
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<table>
<tr>
<td>
<asp:CheckBoxList ID="CheckBoxList1" runat="server">
<asp:ListItem></asp:ListItem></asp:CheckBoxList>
</td>
<td> <asp:Label ID="lblTest" runat="server" Text='<%# Eval("MyColumn") %>'></asp:Label>
</td>
</table>
</ItemTemplate>
</asp:Repeater>
Here is my button:
protected void ButtonSubmit_Click(object sender, EventArgs e)
{
using (SqlConnection sqlConn2 = new SqlConnection(ConfigurationManager.ConnectionStrings["Events2"].ConnectionString))
{
sqlConn2.Open();
using (SqlCommand sqlCmd2 = new SqlCommand())
{
sqlCmd2.Connection = sqlConn2;
sqlCmd2.CommandType = System.Data.CommandType.Text;
foreach (RepeaterItem aItem in Repeater1.Items)
{
CheckBoxList CheckBoxList1 = (CheckBoxList)aItem.FindControl("CheckBoxList1");
foreach (ListItem listItem in CheckBoxList1.Items)
{
if (listItem.Selected == true)
{
sqlCmd2.CommandText = string.Format("UPDATE FormField SET Visible = 0");
sqlCmd2.ExecuteNonQuery();
}
else
{
//do something else
}
}
} sqlConn2.Close();
}
}
}
Your problem is in your SQL. UPDATE without a WHERE will apply to all rows in a table. I'm guessing at your table and data structure, but your solution might look more like this:
CheckBoxList CheckBoxList1 = (CheckBoxList)aItem.FindControl("CheckBoxList1");
foreach (ListItem listItem in CheckBoxList1.Items)
{
if (listItem.Selected)
{
sqlCmd2.CommandText = string.Format("UPDATE FormField SET Visible = 0 WHERE MyField = '{0}';", listItem.Value);
sqlCmd2.ExecuteNonQuery();
}
else
{
//do something else
}
}
Related
I am building a web application to construct a document. The document has paragraphs (outer repeater) and subparagraphs (inner repeater). What I'm looking for is a way to add a blank subparagraph to an existing document.
My markup:
<asp:Repeater ID="ParagraphRepeater" runat="server"
OnItemDataBound="ParagraphRepeater_ItemDataBound" >
<ItemTemplate>
<asp:TextBox ID="ParagraphTitleTextBox" runat="server" Font-Bold="true" Width="300px"
Text='<%# Eval("ParagraphTitle") %>'></asp:TextBox>
<br />
<asp:TextBox ID="ParagraphTextTextBox" runat="server" TextMode="MultiLine" Wrap="true"
width="1100px" Height="50px" Text='<%# Eval("ParagraphText") %>'></asp:TextBox>
<asp:Button ID="DeleteParagraphButton" runat="server" Text="Delete" OnClick="DeleteParagraphButton_Click" />
<asp:Repeater ID="SubParagraphRepeater" runat="server" DataSourceID="SubParagraphSqlDataSource">
<ItemTemplate>
<div style="margin-left: 30px">
<asp:TextBox ID="SubParagraphTitleTextBox" runat="server" Font-Underline="true" Width="200px"
Text='<%# Eval("SubParagraphTitle") %>'></asp:TextBox>
<br />
<asp:TextBox ID="SubParagraphTextTextBox" runat="server" TextMode="MultiLine" Wrap="true"
Width="1050px" Height="50px" Text='<%# Eval("SubParagraphText") %>'></asp:TextBox>
<asp:Button ID="DeleteSubParagraphButton" runat="server" Text="Delete"
OnClick="DeleteSubParagraphButton_Click" />
<br />
</div>
</ItemTemplate>
</asp:Repeater>
<br />
<br />
<br />
</ItemTemplate>
My code:
protected void MultiView1_ActiveViewChanged(object sender, EventArgs e)
{
if (MultiView1.GetActiveView() == InputView)
{
BuildParagraphDataTable();
BuildSubParagraphDataTable();
if (RevisionsDropDownList.SelectedValue == "0")
{
// User is creating a new document
// Call method to create a datatable for the form row
SetFormRow();
// Call method to create a datatable for the paragraph row
AddParagraph();
DataTable dt = (DataTable)ViewState["ParagraphTable"];
ParagraphRepeater.DataSource = dt;
ParagraphRepeater.DataBind();
}
else
{
// User is opening an existing document
// Get the formId and save it to ViewState
int formId = Convert.ToInt32(RevisionsDropDownList.SelectedValue);
ViewState["FormId"] = formId.ToString();
// Bind the Paragraph repeater to its sqlDataSource
ParagraphRepeater.DataSource = ParagraphSqlDataSource;
ParagraphRepeater.DataBind();
}
}
}
protected void AddParagraph()
{
int paragraphId;
DataTable dt = (DataTable)ViewState["ParagraphTable"];
DataRow dr = dt.NewRow();
if (ViewState["ParagraphId"] != null)
paragraphId = Convert.ToInt32(ViewState["ParagraphId"]);
else
paragraphId = 0;
paragraphId--;
int formId = Convert.ToInt32(ViewState["FormId"]);
dr["ParagraphId"] = paragraphId;
dr["FormId"] = formId;
dr["ParagraphTitle"] = string.Empty;
dr["ParagraphText"] = string.Empty;
dr["CreatorId"] = string.Empty;
dr["RevisorId"] = string.Empty;
dt.Rows.Add(dr);
ViewState["ParagraphTable"] = dt;
ViewState["ParagraphId"] = paragraphId;
}
protected void AddSubParagraph()
{
DataTable dt = (DataTable)ViewState["SubParagraphTable"];
DataRow dr = dt.NewRow();
int paragraphId = Convert.ToInt32(ViewState["ParagraphId"]);
dr["ParagraphId"] = paragraphId;
dr["SubParagraphTitle"] = string.Empty;
dr["SubParagraphText"] = string.Empty;
dr["CreatorId"] = string.Empty;
dr["RevisorId"] = string.Empty;
dt.Rows.Add(dr);
ViewState["SubParagraphTable"] = dt;
}
protected void ParagraphRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
AddParagraph();
DataTable parentDataTable = (DataTable)ViewState["ParagraphTable"];
DataRow lastDTRow = parentDataTable.Rows[parentDataTable.Rows.Count - 1];
int paragraphId = (int)ViewState["ParagraphId"];
DataRowView thisParagraphRowView = (DataRowView)e.Item.DataItem;
paragraphId = (int)thisParagraphRowView.Row["ParagraphId"];
lastDTRow["ParagraphId"] = thisParagraphRowView.Row["ParagraphId"];
lastDTRow["FormId"] = thisParagraphRowView.Row["FormId"];
lastDTRow["ParagraphTitle"] = thisParagraphRowView.Row["ParagraphTitle"];
lastDTRow["ParagraphText"] = thisParagraphRowView.Row["ParagraphText"];
ViewState["ParagraphTable"] = parentDataTable;
ViewState["ParagraphId"] = paragraphId.ToString();
DataTable childDataTable;
DataRowView thisSubParagraphRowView;
Repeater childRepeater = (Repeater)e.Item.FindControl("SubParagraphRepeater");
foreach (RepeaterItem item in childRepeater.Items)
{
if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem)
{
thisSubParagraphRowView = (DataRowView)item.DataItem;
if (thisSubParagraphRowView != null)
{
AddSubParagraph();
childDataTable = (DataTable)ViewState["SubParagraphTable"];
lastDTRow = childDataTable.Rows[childDataTable.Rows.Count - 1];
lastDTRow["ParagraphId"] = thisSubParagraphRowView.Row["ParagraphId"];
lastDTRow["SubParagraphTitle"] = thisSubParagraphRowView.Row["SubParagraphTitle"];
lastDTRow["SubParagraphText"] = thisSubParagraphRowView.Row["SubParagraphText"];
ViewState["SubParagraphTable"] = childDataTable;
}
}
}
}
}
When the user opens an existing form, the itemDataBound code populates the datatables for the paragraphs and subparagraphs. (These datatables will be used in the update to the database.)
When the user creates a new form, the setForm() and addParagraph() methods are called to create the form ID and add a blank paragraph. No blank subparagraph is added - the user must click a button to do so.
As for the data model, there is one Form (the user selects it from a ddl). A Form can have 1 to many paragraphs, and paragraphs can have zero to many subparagraphs.
I need to create a blank row in the inner repeater for a particular row in the outer repeater (the paragraph that the cursor is currently located in, or if the cursor is located in a subparagraph, the parent paragraph). How do I do that? I've done a ton of digging on Google but cannot find an entry that addresses this issue. Thanks.
The answer is to move the "AddSubParagraph" button from a standalone position to be inside the outer repeater. That way, the repeater can be located by using the "NamingContainer" attribute of the button. Then it's a matter of finding the inner repeater Repeater innerRepeater = (Repeater)outerRepeater.FindControl("childRepeater");, and adding a row to it. I can add the row but I'm having trouble DataBinding the inner repeater.
What I do is keep datatables in viewstate for each repeater, and mirror the data between the repeaters and the datatables. When I need to add a row, I add it to the datatable and then databind the repeater to the datatable. But I get an error: The line it errors on is childRepeater.Datasource = dt;. The error is "DataSource and DataSourceId are both defined. Remove one definition." DataSourceId is defined on the childRepeater in the markup, pointing to a SQLDataSource. So I need to find a way to bind the inner repeater to its SQLDataSource at retrieval time, on the fly.
One snag: I'm thinking I'd use the ItemDataBound event to do the databinding. But I already have a lot of code there (see above). Is there another event I can use that makes sense?
I have listview in asp.net web form . I want to select rows and update selected after button click.
For this i want to use Checkbox/CheckboxList . But i don't understand how to send information about row or from column in selected row to Checkbox/CheckboxList item .
How can i select rows, and update them , using Checkbox/CheckboxList ?
I use Asp.net Linq Entity Framework.
My code
<asp:Button ID="ButtonTest" runat ="server" OnClick="ButtonTest_Click" />
<asp:ListView ID="ListView2" ItemType="DocCat.Models.ReqInf" SelectMethod="GetReqF" OnItemDataBound="ListView2_ItemDataBound"
DataKeyNames="requestN" EnableViewState="true" runat="server" UpdateMethod="ListView2_UpdateItem" DeleteMethod="ListView2_DeleteItem" InsertMethod="ListView2_InsertItem">
<LayoutTemplate>
<div class="outerContainer" style="overflow: scroll">
<table id="docTable">
<thead>
<tr>
<th>
Выбрать
</th>
<th>First</th>
<th>Request</th>
<th>Third</th>
<th>Four</th>
</tr>
</thead>
<tbody runat="server" id="itemPlaceholder"></tbody>
</table>
</div>
</LayoutTemplate>
<ItemTemplate>
<tr>
<td> <asp:CheckBoxList runat="server" ID="CheckNew" ><asp:ListItem>Выбрать</asp:ListItem></asp:CheckBoxList></td>
<td>
</td>
<td><%# Item.BirthDate.Date%></td>
<td><%# Item.F1 %></td>
<td><%# Item.F2 %></td>
<td><%# Item.F3 %></td>
</tr>
</ItemTemplate>
</asp:ListView>
Selected rows don't display in Checkboxlist items and in string selectedItems :
CheckBoxList cblRoles = ListView2.Items[0].FindControl("CheckNew") as CheckBoxList;
string selectedItems = "";
for (int i = 0; i < cblRoles.Items.Count; i++)
{
if (cblRoles.Items[i].Selected)
{
selectedItems = selectedItems + cblRoles.Items[i].Value + ",";
}
}
I recently used this kind of UI. First I created Table UI, I created populate Table method in my code behind.I used ADO.net for Data Access.
Note: Create stored procs for getting the data and updating the data after button click.
Step1: Write Populate Table method in that create object for checkbox but I used radio Button.
using (mTableRow = new HtmlTableRow()){
{
#region Radio Button
using (HtmlTableCell lTableCell = new HtmlTableCell())
{
RadioButton mradioButton = new RadioButton();
mradioButton.ID = "Radio" + listInfo.ID;
mradioButton.GroupName = "rowSelector1";
mradioButton.AutoPostBack = true;
mradioButton.Checked = false;
mradioButton.CheckedChanged += new EventHandler(AvailableRadioButton_CheckedChanged);
lTableCell.Attributes["class"] = "RadioButton";
lTableCell.Controls.Add(mradioButton);
mTableRow.Cells.Add(lTableCell);
#endregion
// add all the remaining columns
// add table row to the table.
Step2: Create a method for event click of Checkbox.
My problem was to find checkbox, i just missed this :
foreach (ListViewDataItem item in this.ListView2.Items)
{
if (item.ItemType == ListViewItemType.DataItem)
{
and all is working .
My button_click method:
List<int> ls = new List<int>();
{
foreach (ListViewDataItem item in this.ListView2.Items)
{
if (item.ItemType == ListViewItemType.DataItem)
{
CheckBox chkRow = item.FindControl("CheckBox") as CheckBox;
if (chkRow.Checked)
{
int request = int.Parse((item.FindControl("FirstFind") as Label).Text.Trim());
ls.Add(request);
}
}
}
repository.Approved(ls, newstat);
Update Method
public void Approved(List<int> list,int stat )
{
var friends = context.Requery.Where(f => list.Contains(f.parametr)).ToList();
friends.ForEach(a =>
{
a.par1 = 0;
a.par2 = stat;
});
context.SaveChanges();
}
Currently i have two problems.
Problem 1. Im trying to change the Visibility of two Panels based on what value the reader gets from reader["Maskine_Type"].ToString() as you can see in the Codebehind below. Because the Panels are inside a repeater i also use the:
Panel PanelTilbud = (Panel)Page.FindControl("PanelTilbud"); again you can see below. however, when i run the code it gives me a Object reference not set to an instance of an object on PanelTilbud.Visible = true; i assume because it still cant find the Panels. i tested with panels outside of the repeater and it works fine.
I also tried to make the Repeater OnItemDataBound="Repeater1_ItemDataBound"
and changed to Panel PanelTilbud = (Panel)e.Item.FindControl("PanelTilbud");
However then i get the error Insufficient stack to continue executing the program safely
Problem 2.
Inside one of the panels, i run this code
<%# (Eval("Maskine_Tilbud").ToString().Substring(Eval("Maskine_Tilbud").ToString().Length - 2))%>
in order to remove the first two characters in the string from Eval("Maskine_Tilbud") which works fine, however most records in the database will have a null inMaskine_Tilbud and if its null i get the error StartIndex cannot be less than zero which makes sense, but i dont know how else to remove the first two characters from Eval("Maskine_Tilbud")
.aspx markup
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<asp:Panel ID="PanelTilbud" runat="server" Visible="false">
<hr />
<h4 class="radfont text-center">Tilbud! -<%# (Eval("Maskine_Tilbud").ToString().Substring(Eval("Maskine_Tilbud").ToString().Length - 2))%>% pr dag!</h4>
</asp:Panel>
<asp:Panel ID="PanelNormal" runat="server">
<hr />
<h4 class="text-center orangeFont"><%#Eval("Maskine_pris") %><span class="hvidfont">,- pr dag inkl moms</span>
<span class="orangeFont">(<%#Eval("Maskine_Upris") %>,- ekskl)</span>
</h4>
<hr />
</asp:Panel>
</ItemTemplate>
</asp:Repeater>
My Codebehind - in Page_Load
SqlConnection conn = new SqlConnection();
conn.ConnectionString = ConfigurationManager.ConnectionStrings["DatabaseConnectionString1"].ToString();
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandText = "SELECT top 1 * FROM [Maskiner] INNER JOIN Maskine_kategori ON Maskiner.Maskine_Kategorinavn = Maskine_kategori.Maskine_kategori_id WHERE ([Maskine_id] = #Maskine_id)";
cmd.Parameters.Add("#Maskine_id", SqlDbType.Int).Value = Request.QueryString["Maskine_id"];
conn.Open();
SqlDataReader reader = cmd.ExecuteReader();
Panel PanelTilbud = (Panel)Page.FindControl("PanelTilbud");
Panel PanelNormal = (Panel)Page.FindControl("PanelNormal");
if (reader.Read())
{
if (reader["Maskine_Type"].ToString() == "Tilbud")
{
PanelTilbud.Visible = true;
PanelNormal.Visible = false;
}
if (reader["Maskine_Type"].ToString() == "Normal")
{
PanelTilbud.Visible = false;
PanelNormal.Visible = true;
}
}
conn.Close();
DataTable select_favorit_db = new DataTable();
SqlDataAdapter dt = new SqlDataAdapter(cmd);
dt.Fill(select_favorit_db);
Repeater1.DataSource = select_favorit_db;
Repeater1.DataBind();
I hope you can understand my questions.
Late to the party here. Just thought I should add that you can have methods in your page and use them in your data binding expressions. Sample:
ASPX:
<form id="form1" runat="server">
<asp:Repeater ID="rep" runat="server">
<ItemTemplate>
<asp:Label ID="lab" runat="server"
Text='<%# Trim2Chars(Eval("test")) %>'></asp:Label>
</ItemTemplate>
</asp:Repeater>
</form>
Code behind:
protected void Page_Load(object sender, EventArgs e)
{
//create fake data for demo and bind to repeater
var data = Enumerable.Range(0, 10).Select(i => new { test = "foo " + i });
rep.DataSource = data;
rep.DataBind();
}
public string Trim2Chars(object input)
{
string inputString = input as string;
if (inputString == null)
return "";
if (inputString.Length < 2)
return inputString;
return inputString.Substring(2);
}
This way, you can keep the ASPX file a bit cleaner and have more complex data binding expressions evaluated in the code behind.
You can set the Visibility in the Control itself
<asp:Panel ID="PanelTilbud" runat="server" Visible='<%# Eval("Maskine_Type").ToString() == "myValue" %>'>
</asp:Panel>
Or in the ItemDataBound event code behind
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
//use findcontrol to find the panel and cast it as one
Panel panel = e.Item.FindControl("PanelTilbud") as Panel;
//get the current datarowview
DataRowView row = e.Item.DataItem as DataRowView;
//check the value and change the panel visibility
if (row["Maskine_Type"].ToString() == "myValue")
{
panel.Visible = true;
}
}
To check for NULL values you have to use a ternary operator.
<%# !string.IsNullOrEmpty(Eval("Maskine_Type").ToString()) ? Eval("Maskine_Type").ToString().Substring(0, Eval("Maskine_Type").ToString().Length - 2) : "Field is empty" %>
I have a web form where I need to group items/rows based on some criteria. It has multilevel grouping and that is why rendering items in the gird becomes very tedious process for the server.
Here is what I do currently. (This is for only 3 level).
protected void ResultGrid_PreRender(object sender, EventArgs e)
{
foreach (GridViewRow gdR in ResultGrid.Rows)
{
Label lblClass = (Label)gdR.FindControl("lblClass");
Label lblCategory = (Label)gdR.FindControl("lblCategory");
Label lblCompartment = (Label)gdR.FindControl("lblCompartment");
Panel pnlClassLinks = (Panel)gdR.FindControl("pnlClassLinks");
foreach (GridViewRow gdRIn in ResultGrid.Rows)
{
if (gdRIn.RowIndex != gdR.RowIndex)
{
Label lblClassIn = (Label)gdRIn.FindControl("lblClass");
Label lblCategoryIn = (Label)gdRIn.FindControl("lblCategory");
Label lblCompartmentIn = (Label)gdRIn.FindControl("lblCompartment");
if(lblClassIn.Text == lblClass.Text)
{
if(lblCategoryIn.Text == lblCategory.Text)
{
if(lblCompartmentIn.Text == lblCompartment.Text)
{
LinkButton lnkBtn = new LinkButton();
// lnkBtn Properties added
pnlClassLinks.Controls.Add(lnkBtn);
if (pnlClassLinks.Controls.Count > 2)
{
pnlClassLinks.Width = 150;
}
if (gdR.Visible)
{
dr.Visible = false;
}
}
}
}
}
}
LinkButton lnkGroupEdit = (LinkButton)gdR.FindControl("lnkGroupEdit");
lnkGroupEdit.OnClientClick = "editGroup();";
}
}
As it clearly shows, the rows iteration is too much, when the number of rows in gridview increases. So, is there any better way to do this?
You can create a GenericCollection. Include your customised properties like (width, cssClass, visibility...). Then bind this collection to the gridView as a dataSource.
gridView.DataSource= List_CustomModel;
gridView.DataBind();
this is a scope from a code i manipulate
`
<asp:TemplateField>
<HeaderTemplate>
<asp:Literal ID="LtBodac" runat="server" Text="BODACC" />
</HeaderTemplate>
<HeaderStyle CssClass="css-bodacc" />
<ItemTemplate>
<asp:TextBox Visible='<%#Eval("Bodacc") %>' ID="TbDateBodac" CssClass="datebox source-manuel css-bodacc CustomDateMercure" runat="server" Text='<%#Eval("DateBodac")%>' /><asp:HiddenField Visible='<%#Eval("Bodacc") %>' ID="HfOldDateBodac" runat="server" Value='<%#Eval("DateBodac")%>' /> </ItemTemplate>
</asp:TemplateField>
NB:#Eval("Bodacc") :Boddac is a property in my model.
I have a repeater for different updates identified by "Update_ID". Each "Update_ID" has a number of images associated to it.
Therefore, I decided to nest a repeater for the images inside the repeater for updates.
The problem is that the image repeater never shows up, even if there is data to show.
Here is the code in ASP.NET:
<asp:Repeater ID="RepeaterUpdates" runat="server" onitemcommand="RepeaterUpdates_ItemCommand">
<ItemTemplate>
<div style="border: thin solid #808080">
<table id="TableUpdates_Repeater" runat="server" style="width:100%; margin:auto; background-image:url(Resources/Icons/white-background.gif)">
<tr>
<td style="width:25%">
<br />
<asp:Label ID="LabelUpdateID_Repeater" runat="server" Text="Update ID" Enabled="false"></asp:Label>
<asp:TextBox ID="TextBoxUpdateID_Repeater" runat="server" Width="50px" Text='<%# Eval("Update_ID") %>' Enabled="false"></asp:TextBox>
</td>
</tr>
</table>
<asp:Repeater ID="RepeaterImages" runat="server">
<ItemTemplate>
<label>Hello</label>
<asp:TextBox Text='<%# DataBinder.Eval(Container.DataItem,"Image_ID") %>' runat="server"></asp:TextBox>
</ItemTemplate>
</asp:Repeater>
</div>
</ItemTemplate>
</asp:Repeater>
Here is the code-behind:
protected void RepeaterUpdates_ItemCommand(object source, RepeaterCommandEventArgs e)
{
SqlConnection conn5 = new SqlConnection(connString);
SqlDataReader rdr5;
RepeaterItem item = e.Item;
TextBox Update_ID = (TextBox)item.FindControl("TextBoxUpdateID_Repeater");
try
{
conn5.Open();
SqlCommand cmd5 = new SqlCommand("SelectImages", conn5);
cmd5.CommandType = CommandType.StoredProcedure;
cmd5.Parameters.Add(new SqlParameter("#update_id", Update_ID.Text));
rdr5 = cmd5.ExecuteReader();
if ((item.ItemType == ListItemType.Item) || (item.ItemType == ListItemType.AlternatingItem))
{
Repeater ImageRepeater = (Repeater)item.FindControl("RepeaterImages");
ImageRepeater.DataSource = rdr5;
ImageRepeater.DataBind();
}
}
finally
{
conn5.Close();
}
}
As previously stated, the child repeater never shows up, even if there is data to display. How can I solve this problem please? Thanks
Rather than onitemcommand, call OnItemDataBound
Change RepeaterCommandEventArgs to RepeaterItemEventArgs
In addition to #Curt. Below is the code.
Code Behind
class Images
{
public int Image_ID;
}
protected void RepeaterUpdates_ItemCommand(object source, RepeaterCommandEventArgs e)
{
RepeaterItem item = e.Item;
TextBox Update_ID = (TextBox)item.FindControl("TextBoxUpdateID_Repeater");
try
{
conn5.Open();
using (SqlCommand cmd5 = new SqlCommand("SelectImages", conn5))
{
cmd5.CommandType = CommandType.StoredProcedure;
cmd5.Parameters.Add(new SqlParameter("#update_id", Update_ID.Text));
List<Images> Lst = new List<Images>();
using (SqlDataReader rdr5 = cmd5.ExecuteReader())
{
while (rdr5.Read())
{
Lst.Add(new Images { Image_ID = Convert.ToInt16(rdr5["Image_ID"]) });
}
if ((item.ItemType == ListItemType.Item) || (item.ItemType == ListItemType.AlternatingItem))
{
Repeater ImageRepeater = (Repeater)item.FindControl("RepeaterImages");
ImageRepeater.DataSource = Lst;
ImageRepeater.DataBind();
}
}
}
}
finally
{
conn5.Close();
}
}
HTML
You should Register ItemBoundData Event
<asp:Repeater ID="rp" runat="server" onitemdatabound="rp_ItemDataBound">
<ItemTemplate></ItemTemplate>
</asp:Repeater>
protected void rp_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
}