如何在ASP.Net中的Div或面板内拉伸Gridview宽度

时间:2016-06-02 08:01:45

标签: javascript c# jquery css asp.net

enter image description here

基于上图。我有一个gridview,我喜欢被拉伸,固定包含整个内部镶嵌的div。问题是它根据内容宽度自动调整。

gridview与javascript命令合并,使标题得到修复。我可以通过在gridview中放置 width = 100%属性来实际获得所需的输出。但是因为它有jquery命令注入,当我包含width属性时,它会导致这个

enter image description here

这是代码

     <div class="GridviewPanelBody">


      <asp:GridView ID="GridView1" runat="server" BackColor="White" BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1px" CellPadding="4" ForeColor="Black" GridLines="Vertical" Font-Size="Smaller" EmptyDataText="No Records Found" ShowHeaderWhenEmpty="True"  AutoGenerateColumns="false" >
<emptydatarowstyle backcolor="white" forecolor="black"/>             
<AlternatingRowStyle BackColor="White" />

    <Columns>
        <asp:BoundField HeaderText="Location" DataField="locationd" />
        <asp:BoundField HeaderText="Retail Partner" DataField="name"   />
        <asp:BoundField HeaderText="FL Area" DataField="sqm"   />
        <asp:BoundField HeaderText="Previous Month" DataField="PreviousMonth" DataFormatString="{0:#,##0.00;(#,##0.00);0}"  />
         <asp:BoundField HeaderText="Current Month" DataField="CurrentMonth" DataFormatString="{0:#,##0.00;(#,##0.00);0}" />
         <asp:BoundField HeaderText="Last Year Month" DataField="LastYearMonth" DataFormatString="{0:#,##0.00;(#,##0.00);0}" />
          <asp:BoundField HeaderText="Sales/SQM" DataField="SALES/SQM"  DataFormatString="{0:#,##0.00;(#,##0.00);0}"/>
          <asp:BoundField HeaderText="Inc/Dec%" DataField="INC/DEC%"  DataFormatString="{0:#,##0.00;}" />

         </Columns>

       <FooterStyle BackColor="#CCCC99" />
       <HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" Height="25px"/>
       <PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />
     <RowStyle BackColor="#F7F7DE" />
     <SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
      <SortedAscendingCellStyle BackColor="#FBFBF2" />
      <SortedAscendingHeaderStyle BackColor="#848384" />
      <SortedDescendingCellStyle BackColor="#EAEAD3" />
      <SortedDescendingHeaderStyle BackColor="#575357" />
  </asp:GridView>

</div>

css的一部分

 .GridviewPanelBody
{
             background-color: #FaFaFa;

             margin-left: auto;

             margin-right: auto;

             overflow: auto;

             height: auto;   

}

enter image description here

1 个答案:

答案 0 :(得分:0)

为您的gridview对象输入width attribut:

#include<iostream>
#include<cstring>
using namespace std;
class Clen{
private:
char name[50];
char surname[50];
int level;
public:
Clen(char n[] = "null", char s[] = "null", int l = 1){
    strcpy(name, n);
    strcpy(surname, s);
    level = l;
}

//operator++
Clen operator++(int){
    Clen temp(*this);
    ++level;
    return temp;
}

//++operator
Clen &operator ++ (){
    ++level;

    return *this;
}

int getLevel(){
    return level;
}

//operator <<
friend ostream &operator << (ostream &output, const Clen &right);

//operator==
friend bool operator == (const Clen &left, const Clen &right);

//operator!=
friend bool operator != (const Clen &left, const Clen &right);

};
ostream &operator << (ostream &output, const Clen &right){
output << right.name << " " << right.surname << ", " << right.level << endl;
return output;
}

bool operator == (const Clen &left, const Clen &right){
if(left.level == right.level)
    return true;

return false;
}

bool operator != (const Clen &left, const Clen &right){
return !(left == right);
}

class Klub{
private:
char name[100];
Clen *clenovi;
int elements;
void copy(const Klub &toCopy){
    strcpy(name, toCopy.name);
    elements = toCopy.elements;

    clenovi = new Clen[elements + 1];
    for(int i = 0; i < elements; i++){
        clenovi[i] = toCopy.clenovi[i];
    }
}

public:
//constructor
Klub(char n[] = "null", Clen c[] = NULL, int e = 0){
    strcpy(name, n);
    elements = e;

    clenovi = new Clen[elements + 1];
    for(int i = 0; i < elements; i++){
        clenovi[i] = c[i];
    }
}
//copy constructor
Klub(const Klub &toCopy){
    copy(toCopy);
}

//assignment operator
Klub &operator = (const Klub &right){
    if(this == &right)
        return *this;
    delete [] clenovi;
    copy(right);

    return *this;
}

//destructor
~Klub(){
    delete [] clenovi;
}

//operator <<
friend ostream &operator << (ostream &output, const Klub &right);


//operator +=
Klub &operator +=(Clen c){
    Clen *temp = clenovi;
    clenovi = new Clen[elements + 1];

    for(int i = 0; i < elements; i++){
        clenovi[i] = temp[i];

    }

    clenovi[elements] = c;
    ++elements;
    delete [] temp;
    return *this;

}

Klub &novKlub(Clen &c){
    Klub newKlub;
    strcpy(newKlub.name, name);

    for(int i = 0; i < elements; i++){
        if(c.getLevel() == clenovi->getLevel()){
            newKlub += clenovi[i];

        }

    }
    return *this;
}
};

ostream &operator << (ostream &output, const Klub &right){
output << right.name << endl;
for(int i = 0; i < right.elements; i++){
    output << right.clenovi[i] << endl;
}

return output;
}
int main()
{
Clen clen;
int n, stepen;
char ime[30], prezime[30];
cin >> ime >> n;
Klub k1(ime); 
for(int i = 0; i < n; i++){
    cin >> ime >> prezime >> stepen;
    Clen c(ime, prezime, stepen);
    k1 += c;
    clen = c; 
}  
Klub k2 = k1.novKlub(clen);
cout << k2;
return 0;
}

并且,将列的AutoSizeMode属性设置为AllCells。