如何通过单击c#中的复选框来获取Id [英] How to fetch Id by clicking checkbox in c#
本文介绍了如何通过单击c#中的复选框来获取Id的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个datalist ...我必须将StudentName与Student Image&还有复选框...现在,如果我选择复选框,我想让那个学生Id ...如何做到这一点?
请帮帮我..
foreach (DataListItem li in dtlistStudent.Items)
{
CheckBox chkSelect =(CheckBox)li.FindControl( chkStudent);
if (chkSelect.Checked == true )
{
int result = 0 ;
int StudentId = Convert.ToInt32(chkSelect.Checked);
result = new ClsTransportationStudent
{
RouteID = Convert.ToInt32(ddlRoute.SelectedValue),
PickPointID = Convert。 ToInt32(ddlPickPoint.SelectedValue),
StudentID = Convert.ToInt32(chkSelect.Checked),
} .Transportation_StudentTransportInsert();
}
}
解决方案
请参阅有关此主题的文章。放置一个带有ID值的隐藏字段并按时获取该值复选框点击。
ASP.NET - 在DataList中获取选中的CheckBox值 [ ^ ]
access-hidden-field-at-code-behind.aspx [ ^ ]
I have a datalist...I have to bind StudentName with Student Image & also checkbox...now if I select checkbox,I want to get that student Id..how to do this??
please help me out..
[EDIT - OP code from comment]
foreach (DataListItem li in dtlistStudent.Items)
{
CheckBox chkSelect = (CheckBox)li.FindControl("chkStudent");
if (chkSelect.Checked == true)
{
int result = 0;
int StudentId = Convert.ToInt32(chkSelect.Checked);
result = new ClsTransportationStudent
{
RouteID = Convert.ToInt32(ddlRoute.SelectedValue),
PickPointID = Convert.ToInt32(ddlPickPoint.SelectedValue),
StudentID = Convert.ToInt32(chkSelect.Checked),
}.Transportation_StudentTransportInsert();
}
}
解决方案
See article on this topic. Put a hidden field with ID value and get that value on time checkbox click.
ASP.NET - Get selected CheckBox value in DataList[^]
access-hidden-field-at-code-behind.aspx[^]
这篇关于如何通过单击c#中的复选框来获取Id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文