我在一个单独的类中有一个方法,它返回一个 GridView 但由于某种原因它不会显示数据。经过进一步调查,我发现 Gridview 已经分配了正确的数据但不显示它!如果我在主类中运行代码,它工作正常!请帮忙!
//黑胶类
public GridView SearchByAlbum(string AlbumName)
{
VinylComm.CommandType = CommandType.StoredProcedure;
VinylComm.CommandText = "AlbumVinylSearch";
SqlParameter VinylAlbumName;
VinylAlbumName = new SqlParameter();
VinylAlbumName.ParameterName = "@AlbumName";
VinylAlbumName.SqlDbType = SqlDbType.VarChar;
VinylAlbumName.SqlValue = AlbumName;
VinylAlbumName.Size = 50;
VinylAlbumName.Direction = ParameterDirection.Input;
VinylComm.Parameters.Add(VinylAlbumName);
GridView gv;
gv = new GridView();
VinylConn.Open();
gv.DataSource = VinylComm.ExecuteReader();
gv.DataBind();
VinylConn.Close();
return gv;
}
//主页
protected void Submit_Click(object sender, EventArgs e)
{
Vinyl v;
v = new Vinyl();
switch (SearchOptions.SelectedIndex)
{
case 0:
GridView1 = v.SearchByAlbum(SearchInput.Text);
break;
default:
break;
}
}
}