我的DATAGRID绑定一张数据表。
DATAGRID中插入一个CHECKBOX的模版列,怎么遍历来确定哪几行被选中,
同时每次要将选中行的某些字段进行赋值操作
DATAGRID中插入一个CHECKBOX的模版列,怎么遍历来确定哪几行被选中,
同时每次要将选中行的某些字段进行赋值操作
解决方案 »
- No persister for: test.model.Person
- AjaxPanel刷新页面问题
- 求思路!!!
- asp.net文件下载,如果本机下载可以,其他客户端访问下载不成功!
- *︻$▅▆▇◤ [捉拿高手]关于static变量与static方法比较的疑问!
- asp.net页面和flash嵌套会发生冲突吗?
- 为什么系统读不出dropdownlist的选择值
- 非常急!!!关于FreeTextBox文本存入数据库的问题~
- datagrid中的选择问题?
- asp.net 布局?
- DataGrid中怎样给HyperLink列添加一个点击事件?并且取得当前点击格子中的内容 多谢!!!
- 菜鸟的问题
我想到的是 是不是可以用Reader来读
符合的就选中
同时赋值我是刚学 呵呵想不到更好的办法了
private void DataGrid1_PreRender(object sender, System.EventArgs e)
{
foreach (DataGridItem item in this.DataGrid1.Controls[0].Controls)
{
if (item.ItemType == ListItemType.Header)
{
CheckBox chkAll=(CheckBox)item.FindControl("chkAll");
System.Text.StringBuilder strScript = new System.Text.StringBuilder("<script language='javascript'> \n");
strScript.Append(" function checkStatus() { \n");
strScript.Append(" var bAll = true; \n");
strScript.Append(" bAll = document.all('" + chkAll.ClientID + "').checked; \n"); for(int i=0; i<DataGrid1.Items.Count ; i++)
{
strScript.Append(" document.all('" + DataGrid1.Items[i].Cells[0].FindControl("chkItem").ClientID + "').checked = bAll; \n");
}
strScript.Append(" } \n");
strScript.Append("</script> \n"); if(!Page.IsClientScriptBlockRegistered("checkStatus"))
{
Page.RegisterClientScriptBlock("checkStatus",strScript.ToString());
}
chkAll.Attributes.Add("onclick","checkStatus()");
return;
}
}
}private void btnSure_Click(object sender, System.EventArgs e)
{
string whereHou ="";
for (int i = 0 ;i < DataGrid1.Items.Count; i++)
{
CheckBox a;
a = (CheckBox)DataGrid1.Items[i].Cells[0].FindControl("chkItem");
bool b;
b = a.Checked;
if (b == true)
{
whereHou +=",'"+DataGrid1.Items[i].Cells[2].Text.ToString()+"'";
}
}
}
前台:
<asp:datagrid id="DataGrid1" runat="server" Width="615px" PageSize="8" PagerStyle-Mode="NumericPages"
PagerStyle-HorizontalAlign="Right" BorderColor="DimGray" BorderWidth="1" GridLines="Both"
CellPadding="3" CellSpacing="0" Font-Name="Verdana" Font-Size="8pt" HeaderStyle-BackColor="#aaaadd"
AlternatingItemStyle-BackColor="#eeeeee" HorizontalAlign="Center">
<AlternatingItemStyle BackColor="#EEEEEE"></AlternatingItemStyle>
<HeaderStyle HorizontalAlign="Center" ForeColor="#404040" BackColor="LightGray"></HeaderStyle>
<Columns>
<asp:TemplateColumn>
<HeaderTemplate>
<asp:CheckBox id="chkAll" runat="server"></asp:CheckBox>
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox id="chkItem" runat="server"></asp:CheckBox>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>
'找在DATAGRID里的那个复选择框
chkFinder = theDataGridItem.FindControl("chkSelectedItem")
If chkFinder.Checked = True Then
'选中的就做相应的操作
End If
Next
{
CheckBox CBox=(CheckBox)this.DataGrid_BudgetItem.Items[i].FindControl("CheckBox1");
{
if(CBox.Checked==true)
{
h.Add("@CollectItemID",ViewState["CollectItemID"]);
h.Add("@BudgetItemID",i.ToString());
obj.InsertRow("Insert_tbgCollectItemBudget",h);
h.Clear();
}
}