Hi ramco1917,
Please refer below sample.
HTML
<asp:Repeater ID="rptBulkData" runat="server" OnItemDataBound="OnItemDataBound">
<HeaderTemplate>
<table>
<tr>
<td>ID</td>
<td>Break</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<asp:HiddenField ID="hfID" runat="server" Value='<%# Eval("ID") %>' />
<asp:HiddenField ID="hfBreak" runat="server" Value='<%# Eval("Break") %>' />
<asp:Literal ID="ltrlNum" runat="server" Text="<%# Container.ItemIndex + 1 %>"></asp:Literal>
</td>
<td>
<asp:DropDownList ID="ddlBreaks" runat="server">
<asp:ListItem Value="1" Text="Yes"></asp:ListItem>
<asp:ListItem Value="0" Text="No"></asp:ListItem>
</asp:DropDownList>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
Namespace
C#
using System.Data;
VB.Net
Imports System.Data
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[] {
new DataColumn("ID"),
new DataColumn("Break")});
dt.Rows.Add("1", "0");
dt.Rows.Add("2", "1");
dt.Rows.Add("3", "2");
rptBulkData.DataSource = dt;
rptBulkData.DataBind();
}
}
protected void OnItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
DropDownList ddlBreak = (DropDownList)e.Item.FindControl("ddlBreaks") as DropDownList;
string breakValue = (e.Item.FindControl("hfBreak") as HiddenField).Value;
if (ddlBreak.Items.FindByValue(breakValue) != null)
{
ddlBreak.Items.FindByValue(breakValue).Selected = true;
}
else
{
ddlBreak.Items.FindByValue("0").Selected = true;
}
}
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
Dim dt As DataTable = New DataTable()
dt.Columns.AddRange(New DataColumn() {
New DataColumn("ID"),
New DataColumn("Break")})
dt.Rows.Add("1", "0")
dt.Rows.Add("2", "1")
dt.Rows.Add("3", "2")
rptBulkData.DataSource = dt
rptBulkData.DataBind()
End If
End Sub
Protected Sub OnItemDataBound(ByVal sender As Object, ByVal e As RepeaterItemEventArgs)
If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType = ListItemType.AlternatingItem Then
Dim ddlBreak As DropDownList = TryCast(CType(e.Item.FindControl("ddlBreaks"), DropDownList), DropDownList)
Dim breakValue As String = (TryCast(e.Item.FindControl("hfBreak"), HiddenField)).Value
If ddlBreak.Items.FindByValue(breakValue) IsNot Nothing Then
ddlBreak.Items.FindByValue(breakValue).Selected = True
Else
ddlBreak.Items.FindByValue("0").Selected = True
End If
End If
End Sub
Screenshot