跳过图像ddl gridview [英] skipping images ddl gridview
本文介绍了跳过图像ddl gridview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的网页上只有一个带有学生ID的下拉列表和一个带有学生图像的gridview。
如果我选择一个学生,GridView必须显示所选学生的所有图像。
问题是,当我选择一个学生时,我的gridview正在跳过前两个值。
我的意思是如果有6个图像gridview只显示4个图像。
这是我的代码:
There is only a drop down list with student ID and a gridview with students' images in my web page.
If I select a student GridView has to show all the images of the selected student.
Problem is when I select a student my gridview is skipping first two values.
I mean if there are 6 images gridview shows only 4 images.
Here is my code:
private void BindGrid()
{
MySqlConnection con = new MySqlConnection(constr);
MySqlCommand cmd = new MySqlCommand("SELECT * FROM images where Image_ID in (" + String.Join(",", getImage_ID()) + ")", con);
MySqlDataAdapter da = new MySqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
gvImages.DataSource = dt;
gvImages.DataBind();
}
private List<int> getImage_ID()
{
List<int> i = new List<int>();
MySqlConnection con = new MySqlConnection(constr);
con.Open();
string query = "Select Come_Image_ID1, Leave_Image_ID from register where Students_ID='" + getStudents_ID() + "' AND Come_Image_ID IS NOT NULL AND Leave_Image_ID IS NOT NULL";
MySqlCommand cmd = new MySqlCommand(query);
cmd.Connection = con;
MySqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
foreach (DbDataRecord s in reader)
{
i.Add(s.GetInt32(0));
i.Add(s.GetInt32(1));
}
}
reader.Close();
return i;
}
这个问题的最佳编码方法是什么?
示例会很好。
What is the best coding practice for this issue?
Examples would be nice.
推荐答案
尝试以下
try with below
while (reader.Read())
{
reader.Add(s.GetInt32(0));
reader.Add(s.GetInt32(1));
}
这篇关于跳过图像ddl gridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文