本文介绍了在asp.net的GridView的固定宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要解决的GridView的宽度。我填的GridView如下;
sorgu =选择urun.urunId为\\没有\\,urun.modelNo为\\型号\\,modelAd为\\型号名称\\,作为bedenAd \\ Beden \\,adet为\\adet \\
+,aciklama为\\Açıklama\\,kesmeTalimat为\\KesimTalimatı\\,atolyeTalimat为\\AtölyeTalimatı\\,yikamaTalimat为\\YıkamaTalimatı\\,utuTalimat为\\UTUTalimatı\\(K4。广告+''+ k4.soyad)为\\Kesim \\(k1.ad +''+ k1.soyad)为\\Atölye\\
+,(k2.ad +''+ k2.soyad)为\\Yıkama\\(k3.ad +''+ k3.soyad)为\\UTU \\(k5.ad +''+ k5.soyad)作为\\KONTROL \\从kullanici K1,K4 kullanici,kullanici K5,K2 kullanici,kullanici K3,型号,beden,urun,fason,isTalimat,硬粒
+,其中urun.urunId = fason.urunId和urun.urunId = isTalimat.urunId和urun.urunId = durum.urunId和model.modelNo = urun.modelNo和beden.bedenNo = urun.bedenNo和
+fason.atolye = k1.id和fason.yikama = k2.id和fason.kesimci = k4.id和fason.kontrol = k5.id和fason.utu = k3.id;
connection.Open();
command.Connection =连接;
command.CommandText = sorgu;
博士= Command.ExecuteReader却();
数据表dtTumISler =新的DataTable();
dtTumISler.Load(DR);
dgvTumIsler.DataSource = dtTumISler;
dgvTumIsler.DataBind();
dr.Close();
connection.close()时;
dtTumISler.Dispose();
下面dgvTumİsler是我的GridView控件。我曾尝试以下code键使固定长度。但它不工作;
的for(int i = 0; I< dgvTumIsler.Columns.Count;我++)
{
dgvTumIsler.Columns [I] .ItemStyle.Width = 100;
}
下面dgvTumİsler.Columns.Count值为1因此,它不工作。有没有办法解决这个问题的方法或有另一种方法,使一个GridView固定宽度。
HTML code:
< ASP:GridView控件ID =dgvTumIsler=服务器背景色=白BORDERCOLOR =#CCCCCC边框=无边框宽度=1px的CELLPADDING = 3OnSelectedIndexChanged =dgvTumIsler_SelectedIndexChanged>
<柱体和GT;
< ASP:CommandField中按钮类型=按钮SelectText =SECShowCancelButton =FALSEShowSelectButton =真/>
< /专栏>
< FooterStyle背景色=白前景色=#000066/>
< HeaderStyle背景色=#006699FONT-粗体=false的前景色=白/>
< PagerStyle背景色=白前景色=#000066HorizontalAlign =左/>
< RowStyle前景色=#000066/>
< SelectedRowStyle背景色=#669999FONT-粗体=真前景色=白/>
< SortedAscendingCellStyle背景色=#F1F1F1/>
< SortedAscendingHeaderStyle背景色=#007DBB/>
< SortedDescendingCellStyle背景色=#CAC9C9/>
< SortedDescendingHeaderStyle背景色=#00547E/>
< / ASP:GridView的>
解决方案
您可以使用的属性来设置一个CSS类并用它来设置宽度
< RowStyle的CssClass =myRow>
...
< ASP:CommandField中按钮类型=按钮SelectText =秒的CssClass =myButton的/>
...
<风格>
.myRow TD {宽度:100像素;}
.mybutton {宽度:100像素}
< /风格>
I want to fix width of gridview. I am filling gridview as following;
sorgu = "select urun.urunId as \"İş No\",urun.modelNo as \"Model No\",modelAd as \"Model Adı\",bedenAd as \"Beden\", adet as \"Adet\""
+ ",aciklama as \"Açıklama\", kesmeTalimat as \"Kesim Talimatı\", atolyeTalimat as \"Atölye Talimatı\", yikamaTalimat as \"Yıkama Talimatı\", utuTalimat as \"Ütü Talimatı\", (k4.ad+' '+k4.soyad) as \"Kesim\", (k1.ad+' '+k1.soyad) as \"Atölye\""
+ ",(k2.ad+' '+k2.soyad) as \"Yıkama\",(k3.ad+' '+k3.soyad) as \"Ütü\", (k5.ad+' '+k5.soyad) as \"Kontrol\" from kullanici k1,kullanici k4,kullanici k5,kullanici k2,kullanici k3,model,beden,urun,fason,isTalimat,durum"
+ " where urun.urunId= fason.urunId and urun.urunId=isTalimat.urunId and urun.urunId=durum.urunId and model.modelNo=urun.modelNo and beden.bedenNo=urun.bedenNo and"
+ " fason.atolye=k1.id and fason.yikama=k2.id and fason.kesimci=k4.id and fason.kontrol=k5.id and fason.utu=k3.id";
connection.Open();
command.Connection = connection;
command.CommandText = sorgu;
dr = command.ExecuteReader();
DataTable dtTumISler = new DataTable();
dtTumISler.Load(dr);
dgvTumIsler.DataSource = dtTumISler;
dgvTumIsler.DataBind();
dr.Close();
connection.Close();
dtTumISler.Dispose();
Here dgvTumİsler is my gridview. I have tried the following code to make fixed length. But it does not work;
for (int i = 0; i < dgvTumIsler.Columns.Count; i++)
{
dgvTumIsler.Columns[i].ItemStyle.Width = 100;
}
Here dgvTumİsler.Columns.Count value is 1. So it does not work. Is there a way to solve this problem or is there another way to make a gridview fixed width.
HTML code:
<asp:GridView ID="dgvTumIsler" runat="server" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="3" OnSelectedIndexChanged="dgvTumIsler_SelectedIndexChanged">
<Columns>
<asp:CommandField ButtonType="Button" SelectText="Seç" ShowCancelButton="False" ShowSelectButton="True" />
</Columns>
<FooterStyle BackColor="White" ForeColor="#000066" />
<HeaderStyle BackColor="#006699" Font-Bold="false" ForeColor="White" />
<PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
<RowStyle ForeColor="#000066" />
<SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F1F1F1" />
<SortedAscendingHeaderStyle BackColor="#007DBB" />
<SortedDescendingCellStyle BackColor="#CAC9C9" />
<SortedDescendingHeaderStyle BackColor="#00547E" />
</asp:GridView>
解决方案
You can use the CssClass attribute to set a css class and use that to set the width
<RowStyle CssClass="myRow">
...
<asp:CommandField ButtonType="Button" SelectText="Seç" CssClass="mybutton"/>
...
<style>
.myRow td{width: 100px;}
.mybutton{width: 100px}
</style>
这篇关于在asp.net的GridView的固定宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!