i want to learn how to add data in datagrid programatically in asp.net with c#. i want all code like connection string and all the thing i want to learn. please help i need it very urgently.
Can any body give me code for how to add data in datagrid programatically in asp.net with c#?
this is how we did it.....we filled it with objects through an object data source. You can get your source from anything though (pasting code here sucks....)
%26lt;asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="GetAllOrders"
TypeName="DBAccess"%26gt;
%26lt;FilterParameters%26gt;
%26lt;asp:QueryStringParameter DefaultValue="" Name="SearchParam" QueryStringField="Search"
Type="String" /%26gt;
%26lt;asp:QueryStringParameter DefaultValue="" Name="CategoriesParam" QueryStringField="Cat"
Type="Int32" /%26gt;
%26lt;/FilterParameters%26gt;
%26lt;/asp:ObjectDataSource%26gt;
%26lt;asp:GridView ID="GridView_Orders" CssClass="datagrid" runat="server" AllowPaging="True" AutoGenerateColumns="False"
DataSourceID="ObjectDataSource1" PageSize="15" BackColor="White" BorderColor="#CCCCCC"
BorderStyle="None" BorderWidth="1px" CellPadding="3" OnSelectedIndexChanged="GridView_Orders_...
%26lt;Columns%26gt;
%26lt;asp:CommandField ShowSelectButton="True" /%26gt;
%26lt;asp:BoundField DataField="OrderID" HeaderText="OrderID" SortExpression="OrderID" /%26gt;
%26lt;asp:BoundField DataField="CustID" HeaderText="CustID" SortExpression="CustID" /%26gt;
%26lt;asp:BoundField DataField="OrderDate" HeaderText="OrderDate" SortExpression="OrderDate" /%26gt;
%26lt;asp:BoundField DataField="ShipDate" HeaderText="ShipDate" SortExpression="ShipDate" /%26gt;
%26lt;asp:BoundField DataField="Shipper" HeaderText="Shipper" SortExpression="Shipper" /%26gt;
%26lt;asp:HyperLinkField DataTextField="Cost" DataTextFormatString="{0:c}" HeaderText="Cost" /%26gt;
%26lt;/Columns%26gt;
%26lt;FooterStyle BackColor="White" ForeColor="#000066" /%26gt;
%26lt;RowStyle ForeColor="#000066" CssClass="datagrid" /%26gt;
%26lt;SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" /%26gt;
%26lt;PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Center" /%26gt;
%26lt;HeaderStyle BackColor="#006699" Font-Bold="True" CssClass="datagrid" /%26gt;
%26lt;/asp:GridView%26gt;
Then for your connection string....we put that in the web.config file. Looks something like this.
%26lt;?xml version="1.0"?%26gt;
%26lt;configuration xmlns="http://schemas.microsoft.com/.Net...
%26lt;appSettings/%26gt;
%26lt;connectionStrings%26gt;
%26lt;remove name="LocalSqlServer"/%26gt;
%26lt;add name="LocalSqlServer" connectionString="Data Source=192.168.11.11;Initial Catalog=Ecommerce1; User=namehere;Password=ttGurVBx" /%26gt;
%26lt;/connectionStrings%26gt;
%26lt;/configuration%26gt;
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment