TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Tri Setia
1.3k
464
24.8k
How to populate data from Repeater to modal bootstrap in asp.net
Mar 3 2021 4:56 AM
I will bind data from Repeater1 to modal. If user click LinkButton1 on Repeater1 I want the data populate to modal, but l’m din’t get the data although the modal is showing.
<asp:Content ID=
"Content2"
ContentPlaceHolderID=
"ContentPlaceHolder1"
runat=
"Server"
>
<!—This is the my Repeater1-->
<asp:Repeater ID=
"Repeater1"
runat=
"server"
>
<HeaderTemplate>
<table id=
"myTable"
class
=
"table table-hover table-responsive table-borderless"
>
<thead
class
=
"table table-dark"
>
<tr
class
=
"text-center"
>
<th>Nomer ID</th>
<th>Tanggal Muat</th>
<th>Nama Driver</th>
<th>Nomer Lambung</th>
<th>Nomer DO</th>
<th>Jumlah Tonase Pengiriman</th>
<th>Tanggal Timbang Diport</th>
<th>Jumlah Tonase Penerimaan</th>
<th>Nomer CRF</th>
<th>Ngesub Ke Tambang</th>
<th>Selisih</th>
<th>Persentase</th>
<th>Pinalti</th>
<th>Keterangan</th>
<th>#</th>
</tr>
</thead>
<tbody>
</HeaderTemplate>
<ItemTemplate>
<tr
class
=
"text-center"
>
<td>
<asp:Label ID=
"Label1"
runat=
"server"
Text=
'<%#Eval("no_id")%>'
></asp:Label>
</td>
<td>
<%#Eval(
"tgl_muat"
,
"{0: dd/MM/yyyy}"
)%>
</td>
<td>
<%#Eval(
"nama_driver"
)%>
</td>
<td>
<%#Eval(
"no_lambung"
)%>
</td>
<td>
<%#Eval(
"no_do"
)%>
</td>
<td>
<%#Eval(
"tonase_pengiriman"
)%>
</td>
<td>
<%#Eval(
"tgl_timbang_diport"
,
"{0: dd/MM/yyyy}"
)%>
</td>
<td>
<%#Eval(
"tonase_penerimaan"
)%>
</td>
<td>
<%#Eval(
"no_crf"
)%>
</td>
<td>
<%#Eval(
"ngesub_ke_tambang"
)%>
</td>
<td>
<%#Eval(
"selisih"
)%>
</td>
<td>
<%#Eval(
"persentase"
) %>
</td>
<td>
<%#Eval(
"pinalti"
)%>
</td>
<td>
<%#Eval(
"keterangan"
)%>
</td>
<td>
<asp:LinkButton ID=
"LinkButton1"
OnClick=
"LinkButton1_Click"
data-toggle=
"modal"
data-target=
"#ModalDetilData"
data-backdrop=
"static"
class
=
"fa fa-edit btn btn-warning btn-sm"
runat=
"server"
> Detail</asp:LinkButton>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</tbody> </table>
</FooterTemplate>
</asp:Repeater>
<!—This is the modal -->
<!-- Start The Modal DetaiDataCoal -->
<div id=
"ModalDetilData"
class
=
"modal fade"
data-keyboard=
"false"
>
<div
class
=
"modal-dialog modal-lg"
>
<div
class
=
"modal-content"
>
<!-- Modal Header -->
<div
class
=
"modal-header bg bg-blue"
>
<div align=
"center"
>
<h4
class
=
"modal-title"
>Detail Data Coal</h4>
</div>
<button type=
"button"
class
=
"close"
data-dismiss=
"modal"
>
×</button>
</div>
<!-- Modal body -->
<div
class
=
"modal-body"
>
<div
class
=
"row"
>
<div
class
=
"col-md-12"
>
<div
class
=
"card"
>
<div
class
=
"card-body"
>
<div
class
=
"row"
>
<div
class
=
"col-md-6"
>
<div
class
=
"form-group"
>
<label
for
=
"NoID"
>
Nomer ID</label>
<asp:TextBox ID=
"txtNoID"
runat=
"server"
CssClass=
"form-control"
placeholder=
""
></asp:TextBox>
</div>
</div>
<div
class
=
"col-md-6"
>
<div
class
=
"form-group"
>
<label
for
=
"UserName"
>
Tanggal Muat</label>
<asp:TextBox ID=
"txtDetailTanggalMuat"
runat=
"server"
CssClass=
"form-control"
placeholder=
" Enter Tanggal Muat Dari Tambang"
></asp:TextBox>
</div>
</div>
<div
class
=
"col-md-6"
>
<div
class
=
"form-group"
>
<label
for
=
"Password"
>
Nama Driver</label>
<asp:TextBox ID=
"txtDetilDataNamaDriver"
runat=
"server"
CssClass=
"form-control"
placeholder=
"Enter Nama Driver"
></asp:TextBox>
</div>
</div>
<div
class
=
"col-md-6"
>
<div
class
=
"form-group"
>
<label
for
=
"UserName"
>
Nomer Lambung</label>
<asp:TextBox ID=
"txtDetilDataNomerLambung"
runat=
"server"
CssClass=
"form-control"
placeholder=
"Enter Nomer Lambung"
></asp:TextBox>
</div>
</div>
<div
class
=
"col-md-6"
>
<div
class
=
"form-group"
>
<label
for
=
"Password"
>
Nomer DO</label>
<asp:TextBox ID=
"txtDetilDataNomerDO"
runat=
"server"
CssClass=
"form-control"
placeholder=
"Enter Nomer DO"
></asp:TextBox>
</div>
</div>
<div
class
=
"col-md-6"
>
<div
class
=
"form-group"
>
<label
for
=
"UserName"
>
Jumlah Tonase Pengiriman</label>
<asp:TextBox ID=
"txtDetilDataJumlahTonasePengiriman"
runat=
"server"
CssClass=
"form-control"
placeholder=
"Enter Jumlah Tonase Pengiriman"
></asp:TextBox>
</div>
</div>
<div
class
=
"col-md-6"
>
<div
class
=
"form-group"
>
<label
for
=
"Password"
>
Tanggal Timbang Diport</label>
<asp:TextBox ID=
"txtDetailTanggalTimbangDiport"
runat=
"server"
CssClass=
"form-control"
placeholder=
"Enter Tanggal Timbang Diport"
></asp:TextBox>
</div>
</div>
<div
class
=
"col-md-6"
>
<div
class
=
"form-group"
>
<label
for
=
"UserName"
>
Jumlah Tonase Penerimaan</label>
<asp:TextBox ID=
"txtDetilDataJumlahTonasePenerimaan"
runat=
"server"
CssClass=
"form-control"
placeholder=
"Enter Jumlah Tonase Penerimaan"
></asp:TextBox>
</div>
</div>
<div
class
=
"col-md-6"
>
<div
class
=
"form-group"
>
<label
for
=
"Password"
>
Nomer CRF</label>
<asp:TextBox ID=
"txtDetilDataNomerCRF"
runat=
"server"
CssClass=
"form-control"
placeholder=
"Enter Nomer CRF"
></asp:TextBox>
</div>
</div>
<div
class
=
"col-md-6"
>
<div
class
=
"form-group"
>
<label
for
=
"Password"
>
Ngesub Ke Tambang</label>
<asp:TextBox ID=
"txtDetilDataNgesubKeTambang"
runat=
"server"
CssClass=
"form-control"
placeholder=
"Enter Ngesub Ke Tambang"
></asp:TextBox>
</div>
</div>
<div
class
=
"col-md-6"
>
<div
class
=
"form-group"
>
<label
for
=
"UserName"
>
Selisih</label>
<asp:TextBox ID=
"txtDetilDataSelisih"
runat=
"server"
CssClass=
"form-control"
placeholder=
"Enter Selisih"
></asp:TextBox>
</div>
</div>
<div
class
=
"col-md-6"
>
<div
class
=
"form-group"
>
<label
for
=
"Password"
>
Persentase</label>
<asp:TextBox ID=
"txtDetilDataPersentase"
runat=
"server"
CssClass=
"form-control"
placeholder=
"Enter Persentase"
></asp:TextBox>
</div>
</div>
<div
class
=
"col-md-6"
>
<div
class
=
"form-group"
>
<label
for
=
"UserName"
>
Pinalti</label>
<asp:TextBox ID=
"txtDetilDataPinalti"
runat=
"server"
CssClass=
"form-control"
placeholder=
"Enter Pinalti"
></asp:TextBox>
</div>
</div>
<div
class
=
"col-md-12"
>
<div
class
=
"form-group"
>
<label
for
=
"Password"
>
Keterangan</label>
<asp:TextBox ID=
"txtDetilDataKeterangan"
TextMode=
"MultiLine"
Height=
"150px"
runat=
"server"
CssClass=
"form-control"
placeholder=
"Enter Keterangan"
></asp:TextBox>
</div>
</div>
<div
class
=
"col-md-6"
>
<div
class
=
"form-group"
>
<div align=
"center"
>
<asp:Button ID=
"btnUpdateDataCoal"
CssClass=
"btn btn-success btn-block"
runat=
"server"
Text=
"Update Data"
OnClick=
"btnUpdateDataCoal_Click"
/>
</div>
</div>
</div>
<div
class
=
"col-md-6"
>
<div
class
=
"form-group"
>
<div align=
"center"
>
<asp:Button ID=
"btnDeleteData"
CssClass=
"btn btn-danger btn-block"
runat=
"server"
Text=
"Delete Data"
OnClick=
"btnDeleteData_Click"
/>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- End The Modal DetaiDataCoal -->
</asp:Content>
<!-- This
is
method
for
show data on the Repeater1 -->
public
void
ShowData()
{
using
(SqlConnection con =
new
SqlConnection(koneksi))
{
using
(SqlCommand sqlcmd =
new
SqlCommand())
{
con.Open();
sqlcmd.Connection = con;
sqlcmd.CommandType = CommandType.Text;
sqlcmd.CommandText =
"Select * From dbo.tbl_coal"
;
SqlDataAdapter adp =
new
SqlDataAdapter(sqlcmd);
DataTable dt =
new
DataTable();
adp.Fill(dt);
Repeater1.DataSource = dt;
Repeater1.DataBind();
con.Close();
}
}
}
<!-- This
is
method
for
bind data from Repeater1 to Modal-->
protected
void
LinkButton1_Click(
object
sender, EventArgs e)
{
RepeaterItem item = (sender
as
LinkButton).Parent
as
RepeaterItem;
int
Id = Convert.ToInt32((item.FindControl(
"Label1"
)
as
System.Web.UI.WebControls.Label).Text);
using
(SqlConnection con =
new
SqlConnection(koneksi))
{
using
(SqlCommand sqlcmd =
new
SqlCommand(
"SPGetByID"
))
{
con.Open();
sqlcmd.Connection = con;
sqlcmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter adp =
new
SqlDataAdapter(sqlcmd);
SqlParameter param =
new
SqlParameter(
"@no_id"
, Id);
sqlcmd.Parameters.Add(param);
using
(SqlDataReader rdr = sqlcmd.ExecuteReader())
{
while
(rdr.Read())
{
txtNoID.Text = rdr[
"no_id"
].ToString();
txtDetailTanggalMuat.Text = rdr[
"tgl_muat"
].ToString();
txtDetilDataNamaDriver.Text = rdr[
"nama_driver"
].ToString();
txtDetilDataNomerLambung.Text = rdr[
"no_lambung"
].ToString();
txtDetilDataNomerDO.Text = rdr[
"no_do"
].ToString();
txtDetilDataJumlahTonasePengiriman.Text = rdr[
"tonase_pengiriman"
].ToString();
txtDetailTanggalTimbangDiport.Text = rdr[
"tgl_timbang_diport"
].ToString();
txtDetilDataJumlahTonasePenerimaan.Text = rdr[
"tonase_penerimaan"
].ToString();
txtDetilDataNomerCRF.Text = rdr[
"no_crf"
].ToString();
txtDetilDataNgesubKeTambang.Text = rdr[
"ngesub_ke_tambang"
].ToString();
txtDetilDataSelisih.Text = rdr[
"selisih"
].ToString();
txtDetilDataPersentase.Text = rdr[
"persentase"
].ToString();
txtDetilDataPinalti.Text = rdr[
"pinalti"
].ToString();
txtDetilDataKeterangan.Text = rdr[
"keterangan"
].ToString();
}
}
con.Close();
}
}
}
Any help could be appreciated
Reply
Answers (
3
)
Is it possible to inject a method in Swagger
how to create web socket to consume mapmyindia API