how to add 2 rows and 2 cols into datagrid

  • Thread starter Thread starter Bill Yin
  • Start date Start date
Hi Bill
you might need to be more clear about what you want to do, also it differs
depending on whether if you are building web or windows application .
if you are using web here is how to add the columns
Here is an example so you can add columns of any types using many ways
<asp:datagrid DataKeyField="DiscId" id="DataGrid1" style="Z-INDEX: 110;
LEFT: 8px; POSITION: absolute; TOP: 408px"
runat="server" AutoGenerateColumns="False" CellPadding="8"
BorderWidth="2px" BorderColor="Yellow">
<HeaderStyle ForeColor="White" BackColor="Indigo"></HeaderStyle>
<Columns>
<asp:BoundColumn DataField="LabelText" HeaderText="DVD Content">
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="Color" HeaderText="Color">
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="DiscImageFile" HeaderText="Image">
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:BoundColumn>
<asp:ButtonColumn Text="Book" ButtonType="PushButton"
HeaderText="Reserve" CommandName="reserve">
<ItemStyle BackColor="Purple"></ItemStyle>
</asp:ButtonColumn>
<asp:TemplateColumn HeaderText="DVD View">
<ItemStyle BackColor="Purple"></ItemStyle>
<ItemTemplate>
<asp:Button runat="server" Text="Details" CommandName="opencontent"
CausesValidation="false"></asp:Button>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>


Note also that you can always use the method rows.add and coloumns.add
that add to the rows and columns collections respectively . you need to
define these rows or columns object before adding them however .

Mohamed Mahfouz
MEA Developer Support Center
ITworx on behalf of Microsoft EMEA GTSC
 
Back
Top