找DATALIST中的控件
我想实现判断RadioButton是否选中,然后更新,可是rb的返回值为空protectedvoidDataList1_Update(objectsource,DataL...
我想实现判断RadioButton 是否选中,然后更新,可是rb的返回值为空
protected void DataList1_Update(object source, DataListCommandEventArgs e)
{
for (int i = 0; i < DataList1.Items.Count; i++)
{
RadioButton rb = new RadioButton();
rb = (RadioButton)DataList1.Items[i].FindControl("rbTop");
string top;
if (rb.Checked)
{
top = "1";
}
else
{
top = "0";
}
string Site_name = ((TextBox)e.Item.FindControl("TextBox1")).Text;
string Content = ((TextBox)e.Item.FindControl("TextBox2")).Text;
string id = DataList1.DataKeys[e.Item.ItemIndex].ToString();
SqlCommand cmd = new SqlCommand("Update Case_Management Set Site_name='" + Site_name + "',Content='" + Content + "',[Top]='" + top + "' Where web_id=" + id, conn);
cmd.ExecuteNonQuery();
DataList1.EditItemIndex = -1;
BindData();
}
有人说应该写到DataList1_ItemCommand里去,那我在DataList1_Update中用到TOP呢 展开
protected void DataList1_Update(object source, DataListCommandEventArgs e)
{
for (int i = 0; i < DataList1.Items.Count; i++)
{
RadioButton rb = new RadioButton();
rb = (RadioButton)DataList1.Items[i].FindControl("rbTop");
string top;
if (rb.Checked)
{
top = "1";
}
else
{
top = "0";
}
string Site_name = ((TextBox)e.Item.FindControl("TextBox1")).Text;
string Content = ((TextBox)e.Item.FindControl("TextBox2")).Text;
string id = DataList1.DataKeys[e.Item.ItemIndex].ToString();
SqlCommand cmd = new SqlCommand("Update Case_Management Set Site_name='" + Site_name + "',Content='" + Content + "',[Top]='" + top + "' Where web_id=" + id, conn);
cmd.ExecuteNonQuery();
DataList1.EditItemIndex = -1;
BindData();
}
有人说应该写到DataList1_ItemCommand里去,那我在DataList1_Update中用到TOP呢 展开
展开全部
foreach (DataListItem item in DataList1.Items)
{
chk = item.FindControl("CheckBox1") as CheckBox;
if (chk != null && chk.Checked)
{
Label lbOne = item.FindControl("lbName") as Label;
//依次寻找你需要的值
if (lbOne != null)
{
//证明找到了
}
}
}
{
chk = item.FindControl("CheckBox1") as CheckBox;
if (chk != null && chk.Checked)
{
Label lbOne = item.FindControl("lbName") as Label;
//依次寻找你需要的值
if (lbOne != null)
{
//证明找到了
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
DataList的ispostback属性设为true就可以了。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
全写到ItemCommand中不就行了
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询