【发布时间】:2012-08-01 09:22:55
【问题描述】:
我在表单中有一个 Radgrid 和 RadCombobox。在一个函数中,我正在调用一个 forloop。在那个forloop中,我正在为网格使用重新绑定事件。在循环中,第一次去网格的NeedDataSource,第二次没有发生Needdatasource事件,
当 Combobox 文本更改时,Grid 应该转到 NeedDataSource 事件。请帮忙。
for (int a = 0; a < EmpCodecmb.Items.Count; a++)
{
EmpCodecmb.Text = EmpCodecmb.Items[a].Text;
EmpCodecmb.SelectedValue = EmpCodecmb.Items[a].Value;
SqlCommand cmd1 = new SqlCommand();
con.Open();
cmd1.Connection = con;
cmd1.CommandType = CommandType.StoredProcedure;
cmd1.Parameters.Clear();
cmd1.CommandText = "get_EmpLeaveDetails";
cmd1.Parameters.AddWithValue("@EmployeeID", EmpCodecmb.SelectedValue);
cmd1.Parameters.AddWithValue("@SelectedMonth", commonDatetime);
SqlDataReader sdp1 = cmd1.ExecuteReader();
while (sdp1.Read())
{
CLtxt.Text = sdp1["CL"].ToString();
ELtxt.Text = sdp1["EL"].ToString();
LOPtxt.Text = sdp1["LOP"].ToString();
}
con.Close();
Grid1.Rebind();
Grid2.Rebind();
Insert_f1();
Insert_f2();
}`
【问题讨论】:
-
在 for 循环中使用 rebind 方法不是一个好方法,您应该提高代码效率。
-
如果您可以在 For Loop 之前创建一个 DataTable 并使用 DataTable..Rows.Add() 添加行然后执行 Bind 会更好
-
@Jigar Pandya,谢谢兄弟,它可以工作 gr8.. 非常感谢...