検索結果を表示するグリッドビューがあります。しかし、さまざまな検索結果で、このグリッドビューのさまざまなサイズが表示され、見栄えがよくありません。ここにあります:
ご覧のとおり、ヒードと列のサイズが変わります。グリッドビューのコードは次のとおりです。
<asp:GridView ID="searchResults" runat="server" AutoGenerateColumns="False" OnSelectedIndexChanged="searchResults_SelectedIndexChanged"
BackColor="White" BorderColor="White" BorderStyle="None" BorderWidth="1px" CellPadding="4"
ForeColor="Black" GridLines="Vertical" style="margin-right: 0px" Width="1018px"
Height="192px">
<RowStyle BackColor="#F7F7DE" />
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="checkboxRegister" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="CRN" HeaderText="CRN" />
<asp:BoundField DataField="CourseCode" HeaderText="Course Code" />
<asp:BoundField DataField="CourseNumber" HeaderText="Course Number" />
<asp:BoundField DataField="Credit" HeaderText="Credit" />
<asp:BoundField DataField="CourseName" HeaderText="Course Name" />
<asp:BoundField DataField="Capacity" HeaderText="Capacity" />
<asp:BoundField DataField="InstructorName" HeaderText="Instructor" />
<asp:BoundField DataField="Level" HeaderText="Level" />
</Columns>
<FooterStyle BackColor="#CCCC99" />
<PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />
<SelectedRowStyle BackColor="#9E51CF" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#564D94" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
そして、ここにデータをバインドする方法があります:
protected void BClassSearch_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection();
con.ConnectionString = Userfunctions.GetConnectionString();
con.Open();
string selected = lbCourseListBox.SelectedValue;
if(selected!="" && Tcoursenumber.Text!="")
{
string query="";
if(MyGlobals.student.getLevel()=="Undergraduate")
query = "select [CRN],[CourseCode],[CourseNumber],[Credit],[CourseName],[Capacity],[InstructorName],[Level] from CourseTable where CourseCode='" + lbCourseListBox.SelectedValue+"' and CourseNumber = '" + Tcoursenumber.Text+"'" + "' and Level='Undergraduate";
else
query="select [CRN],[CourseCode],[CourseNumber],[Credit],[CourseName],[Capacity],[InstructorName],[Level] from CourseTable where CourseCode='" + lbCourseListBox.SelectedValue+"' and CourseNumber = '" + Tcoursenumber.Text+"'";
SqlDataAdapter adap = new SqlDataAdapter(query, con);
DataTable tab = new DataTable();
adap.Fill(tab);
searchResults.DataSource = tab;
searchResults.DataBind();
}
else if (selected != "" && Tcoursenumber.Text == "")
{
string query = "";
if (MyGlobals.student.getLevel() == "Undergraduate")
query = "select [CRN],[CourseCode],[CourseNumber],[Credit],[CourseName],[Capacity],[InstructorName],[Level] from CourseTable where CourseCode='" + lbCourseListBox.SelectedValue+"' and Level='Undergraduate'";
else
query = "select [CRN],[CourseCode],[CourseNumber],[Credit],[CourseName],[Capacity],[InstructorName],[Level] from CourseTable where CourseCode='" + lbCourseListBox.SelectedValue + "'";
SqlDataAdapter adap = new SqlDataAdapter(query, con);
DataTable tab = new DataTable();
adap.Fill(tab);
searchResults.DataSource = tab;
searchResults.DataBind();
}
else if (selected == "" && Tcoursenumber.Text != "")
{
string query="";
if(MyGlobals.student.getLevel()=="Undergraduate")
query = "select [CRN],[CourseCode],[CourseNumber],[Credit],[CourseName],[Capacity],[InstructorName],[Level] from CourseTable where CourseNumber='" + Tcoursenumber.Text+"' and Level='Undergraduate'";
else
query = "select [CRN],[CourseCode],[CourseNumber],[Credit],[CourseName],[Capacity],[InstructorName],[Level] from CourseTable where CourseNumber='" + Tcoursenumber.Text + "'";
SqlDataAdapter adap = new SqlDataAdapter(query, con);
DataTable tab = new DataTable();
adap.Fill(tab);
searchResults.DataSource = tab;
searchResults.DataBind();
}
else if (selected == "" && Tcoursenumber.Text == "")
{
string query = "";
if(MyGlobals.student.getLevel()=="Undergraduate")
query = "select [CRN],[CourseCode],[CourseNumber],[Credit],[CourseName],[Capacity],[InstructorName],[Level] from CourseTable where Level='Undergraduate' order by CourseCode";
else
query = "select [CRN],[CourseCode],[CourseNumber],[Credit],[CourseName],[Capacity],[InstructorName],[Level] from CourseTable order by CourseCode";
SqlDataAdapter adap = new SqlDataAdapter(query, con);
DataTable tab = new DataTable();
adap.Fill(tab);
searchResults.DataSource = tab;
searchResults.DataBind();
}
}
誰でもこれを修正する方法を教えてもらえますか? ここで何か助けていただければ幸いです。ありがとう。