У меня проблемы с невидимой кнопкой ссылок в виде сетки, если в строках нет данных.
Это результат моего кода
мой HTML-код:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
Width="700px" AllowPaging="True"
onpageindexchanging="GridView1_PageIndexChanging" DataKeyNames="ProductId"
onselectedindexchanged="GridView1_SelectedIndexChanged">
<Columns>
<asp:ButtonField Text="view" CommandName="Select">
<ItemStyle Width="100px" />
</asp:ButtonField>
<asp:BoundField HeaderText="ProductId" DataField="ProductId" >
<ItemStyle Width="100px" />
</asp:BoundField>
<asp:BoundField HeaderText="ProductName" DataField="ProductName">
<ItemStyle Width="300px"></ItemStyle>
</asp:BoundField>
<asp:BoundField HeaderText="QuantityPerUnit" DataField="QuantityPerUnit">
<ItemStyle Width="200px"></ItemStyle>
</asp:BoundField>
</Columns>
</asp:GridView>
Мой код Aspx:
public void BindData()
{
string strConnection = @"Data Source=.\sa;Initial Catalog=Northwind;Integrated Security=SSPI;";
SqlConnection con = new SqlConnection(strConnection);
con.Open();
SqlCommand cmd = new SqlCommand("select ProductId, ProductName, SupplierId from Products", con);
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(ds);
//Script row 10
int rowcount = ds.Tables[0].Rows.Count;
int remainingCount = 10 - (rowcount % 10);
for (int i = 0; i < remainingCount; i++)
{
DataRow row = ds.Tables[0].NewRow();
ds.Tables[0].Rows.Add(row);
}
GridView1.DataSource = ds;
GridView1.DataBind();
con.Close();
}
любой может улучшить мой код, пожалуйста ..