为了加入多选
我在页面代码中加入了:
<asp:DataGrid id="DataGrid1" runat="server">
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<input type="hidden" id="SelectedID" runat="server"
value='<%# Container.ItemIndex%>' NAME="SelectedID"/>
<asp:CheckBox ID="chkExport" Runat="server" />
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>在cs文件中写入:
foreach(DataGridItem di in this.DataGrid1.Items)
{
if(((CheckBox)di.FindControl("chkExport")).Checked==true)
{
this.Label8.Text+=this.DataGrid1.DataKeys[int.Parse(((HtmlInputHidden)di.FindControl("SelectedID")).Value)]+"<br>";
}
} 但是选项选中,调试的时候都不进这个if的区域,郁闷很久了!!!!!
求大家救救我
!!
我在页面代码中加入了:
<asp:DataGrid id="DataGrid1" runat="server">
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<input type="hidden" id="SelectedID" runat="server"
value='<%# Container.ItemIndex%>' NAME="SelectedID"/>
<asp:CheckBox ID="chkExport" Runat="server" />
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>在cs文件中写入:
foreach(DataGridItem di in this.DataGrid1.Items)
{
if(((CheckBox)di.FindControl("chkExport")).Checked==true)
{
this.Label8.Text+=this.DataGrid1.DataKeys[int.Parse(((HtmlInputHidden)di.FindControl("SelectedID")).Value)]+"<br>";
}
} 但是选项选中,调试的时候都不进这个if的区域,郁闷很久了!!!!!
求大家救救我
!!
解决方案 »
- Active Directory 问题,The server is not operational.
- [求助] FCKEditor如何粘贴来自Office Word的内容?粘贴过来的图片都变成红叉了。
- 熟悉js ajax的帮忙看下, 小白请教了,来者有分
- 问一下关于cookie问题
- 遇到个问题,帮帮忙吧!!
- 在加100分,问部署数据库
- ASP.NET 的 C#代码里有这样一个语句
- 求数组查询代码!
- Panel里的 控件 绝对位置 转化为 相对位置 ----顺便放分,,,
- 我用c#编写ASPX,A页面调用B页面时要传递参数,但我想用POST方法传递,请大家帮忙!
- 一个关于datagrid实现超链接的问题
- 在glable里做了一个查看在线人员的功能,不知道怎么在关闭页面的时候删了该用户的记录
{
this.DataGrid1.DataSource = ..;
this.DataGrid1.DataBind();
}
{
if(e.Item.ItemIndex <> -1)
{
if(((CheckBox)di.FindControl("chkExport")).Checked==true)
{
this.Label8.Text+=this.DataGrid1.DataKeys[int.Parse(((HtmlInputHidden)di.FindControl("SelectedID")).Value)]+"<br>";
}
}
}
在这里处理
我加了个按钮,没道理选中也不进条件的呀能告诉我措在那里?
这样试试:
CheckBox cb = (CheckBox)di.Cells[*].Controls[*];
Dim Conn As New OleDbConnection("Data Source=""" & Me.Server.MapPath(System.Configuration.ConfigurationSettings.AppSettings("database")) & """;Provider=""Microsoft.Jet.OLEDB.4.0"";User ID=Admin")
Dim i As Integer
Me.Label5.Text = ""
Conn.Open()
For i = 0 To Me.DataGrid1.Items.Count - 1
Dim chk As CheckBox = CType(Me.DataGrid1.Items.Item(i).FindControl("checkbox1"), CheckBox)
Dim chkstr As String = chk.Checked
Dim mycom As New OleDbCommand("UPDATE T_MailRecommendSmtp SET IsEnabled = " & chkstr & " WHERE (ID = " & Me.DataGrid1.Items.Item(i).Cells(0).Text & ")", Conn)
If mycom.ExecuteNonQuery > 0 Then Me.Label2.Text = "操作已经成功!" End If
Next
Conn.Close()
End Sub
CType(Me.DataGrid1.Items.Item(i).FindControl("checkbox1"), CheckBox)
{
this.DataGrid1.DataSource = ..;
this.DataGrid1.DataBind();
}
看看是不是这样,这样的问题很多情况下是绑定问题
private void Page_Load(object sender, System.EventArgs e)
{
L_tname.Text = Request.Cookies["InfoPlat_UserNo"].Value;
String command = "select chname from course,opencourse where course.id=opencourse.courseid and opencourse.teachername = "+"'"+L_tname.Text+"'";
DataSet myDataset = pubsql.sql(command);
for(int i = 0 ;i<myDataset.Tables[0].Rows.Count;i++)
{
D_tCourse.Items.Add(myDataset.Tables[0].Rows[i].ItemArray.GetValue(0).ToString());
}
///////////////////////////////////////////////
command = "select classtime from opencourse where teachername = "+"'"+L_tname.Text+"'"+" and opencourse.courseid = (select id from course where course.chname = "+"'"+D_tCourse.SelectedItem.Text+"'"+")";
myDataset.Reset();
myDataset = pubsql.sql(command);
for (int i= 0 ;i<myDataset.Tables[0].Rows.Count;i++)
{
string [] split=myDataset.Tables[0].Rows[i].ItemArray.GetValue(0).ToString().Split(new Char [] {' '});
for(int j= 0; j<split.Length;j++)
{
D_tCoursetime.Items.Add(split[j]);
}
}
////////////////////////////////////////
command = "select term from opencourse,course where opencourse.teachername = "+"'"+L_tname.Text+"'"+" and course.id=opencourse.courseid and course.chname = "+"'"+D_tCourse.SelectedItem.Text+"'";
myDataset.Reset();
myDataset = pubsql.sql(command);
for (int i= 0 ;i<myDataset.Tables[0].Rows.Count;i++)
{
string [] split=myDataset.Tables[0].Rows[i].ItemArray.GetValue(0).ToString().Split(new Char [] {' '});
for(int j= 0; j<split.Length;j++)
{
D_tTerm.Items.Add(split[j]);
}
}
/////////////////////////////////////////
command = "select stuno as '学号',student.chname as '姓名',sex as '性别',student.grade as '年级' from student,stuselcourse,opencourse,course where stuselcourse.stuid=student.id and stuselcourse.opencourseid=opencourse.id and opencourse.teachername = "+"'"+L_tname.Text+"'"+" and course.chname="+"'"+D_tCourse.SelectedItem.Text+"'"+" and opencourse.term="+"'"+D_tTerm.SelectedItem.Text+"'"+" and course.id=opencourse.courseid order by student.stuno";
// command = "select stuno from student";
DataGrid1.DataSource = pubsql.sql(command);
DataGrid1.DataBind();
}foreach能执行,di.cell[].text也能得到,但是加出来的checkbox就是访问不到!!!
修改为
if(!IsPostBack){
DataGrid1.DataSource = pubsql.sql(command);
DataGrid1.DataBind();
}
否则在PostBack的时候重新绑定导致你选择的丢失
好象是哦!
我以前也经常遇到这个问题1`