0

検索結果を表示するグリッドビューがあります。しかし、さまざまな検索結果で、このグリッドビューのさまざまなサイズが表示され、見栄えがよくありません。ここにあります:

ここに画像の説明を入力

ここに画像の説明を入力

ご覧のとおり、ヒードと列のサイズが変わります。グリッドビューのコードは次のとおりです。

<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();
       }
}

誰でもこれを修正する方法を教えてもらえますか? ここで何か助けていただければ幸いです。ありがとう。

4

1 に答える 1

0

次のように、各アイテムの幅と高さを設定します。

<asp:BoundField DataField="Credit" HeaderText="Credit"  HeaderStyle-Width="100" HeaderStyle-Height="20" ItemStyle-Height="20" ItemStyle-Width="100" />

または、1 つ (または 2 つ) の CSS スタイルを追加し、各項目に追加します。

<asp:BoundField DataField="CourseName" HeaderText="Course Name"  ItemStyle-CssClass="style1" HeaderStyle-CssClass="style" />

高さだけを指定する必要がある場合は、高さだけを設定できます (明らかに)。

于 2013-06-03T14:51:00.423 に答える