|
i want create datagrid programaticaly.i dont want create it from property builder
i want the number of my column be depends on the number of my records in database.
|
|
|
|
|
ICollection CreateDataSource()
{
// Create sample data for the DataGrid control.
DataTable dt = new DataTable();
DataRow dr;
// Define the columns of the table.
dt.Columns.Add(new DataColumn("IntegerValue", typeof(Int32)));
dt.Columns.Add(new DataColumn("StringValue", typeof(string)));
dt.Columns.Add(new DataColumn("CurrencyValue", typeof(double)));
// Populate the table with sample values.
for (int i = 0; i < 9; i++)
{
dr = dt.NewRow();
dr[0] = i;
dr[1] = "Item " + i.ToString();
dr[2] = 1.23 * (i + 1);
dt.Rows.Add(dr);
}
DataView dv = new DataView(dt);
return dv;
}
void Page_Load(Object sender, EventArgs e)
{
// Create a DataGrid control.
DataGrid ItemsGrid = new DataGrid();
// Set the properties of the DataGrid.
ItemsGrid.ID = "ItemsGrid";
ItemsGrid.BorderColor = System.Drawing.Color.Black;
ItemsGrid.CellPadding = 3;
ItemsGrid.AutoGenerateColumns = false;
// Set the styles for the DataGrid.
ItemsGrid.HeaderStyle.BackColor =
System.Drawing.Color.FromArgb(0x0000aaaa);
// Create the columns for the DataGrid control. The DataGrid
// columns are dynamically generated. Therefore, the columns
// must be re-created each time the page is refreshed.
// Create and add the columns to the collection.
ItemsGrid.Columns.Add(CreateBoundColumn("IntegerValue", "Item"));
ItemsGrid.Columns.Add(
CreateBoundColumn("StringValue", "Description"));
ItemsGrid.Columns.Add(
CreateBoundColumn("CurrencyValue", "Price", "{0:c}",
HorizontalAlign.Right));
ItemsGrid.Columns.Add(
CreateLinkColumn("http://www.microsoft.com", "_self",
"Microsoft", "Related link"));
// Specify the data source and bind it to the control.
ItemsGrid.DataSource = CreateDataSource();
ItemsGrid.DataBind();
// Add the DataGrid control to the Controls collection of
// the PlaceHolder control.
Place.Controls.Add(ItemsGrid);
}
BoundColumn CreateBoundColumn(String DataFieldValue,
String HeaderTextValue)
{
// This version of the CreateBoundColumn method sets only the
// DataField and HeaderText properties.
// Create a BoundColumn.
BoundColumn column = new BoundColumn();
// Set the properties of the BoundColumn.
column.DataField = DataFieldValue;
column.HeaderText = HeaderTextValue;
return column;
}
BoundColumn CreateBoundColumn(String DataFieldValue,
String HeaderTextValue, String FormatValue,
HorizontalAlign AlignValue)
{
// This version of CreateBoundColumn method sets the DataField,
// HeaderText, and DataFormatString properties. It also sets the
// HorizontalAlign property of the ItemStyle property of the column.
// Create a BoundColumn using the overloaded CreateBoundColumn method.
BoundColumn column = CreateBoundColumn(DataFieldValue, HeaderTextValue);
// Set the properties of the BoundColumn.
column.DataFormatString = FormatValue;
column.ItemStyle.HorizontalAlign = AlignValue;
return column;
}
HyperLinkColumn CreateLinkColumn(String NavUrlValue,
String TargetValue, String TextValue, String HeaderTextValue)
{
// Create a BoundColumn.
HyperLinkColumn column = new HyperLinkColumn();
// Set the properties of the ButtonColumn.
column.NavigateUrl = NavUrlValue;
column.Target = TargetValue;
column.Text = TextValue;
column.HeaderText = HeaderTextValue;
return column;
}
this is a sample code from msdn, try it
coolsweety
|
|
|
|
|
I have two tables in my table and i want to inser the values in two tables using single queiry is it possible
|
|
|
|
|
To be more clear write an sp to insert data into two tables simultanously
Execute the Procedure
"Aim to go where U have never been B4 and Strive to achieve it"
http://groups.yahoo.com/subscribe/dotnetforfreshers
http://himabinduvejella.blogspot.com
|
|
|
|
|
hi im developing a mail application.im able to send mail through smtp mail .but my requirement is i have to receive mails thro pop3 .i did that thro this code
try {
// You will need to set these to your settings.
// The settings here are settings for a local
// demo POP3 server
// that I use for testing.
string xHost = "127.0.0.1";
string xUsername = "chad";
string xPassword = "pass";
using (POP3 xPOP3 = new POP3()) {
xPOP3.Username = xUsername;
xPOP3.Password = xPassword;
xPOP3.Connect(xHost);
int xCount = xPOP3.CheckMessages();
if (xCount == 0) {
Console.WriteLine("No messages on account.");
}
else {
Message xMsg = new Message();
xPOP3.Retrieve(1, xMsg);
Console.WriteLine("Subject: " + xMsg.Subject);
Console.WriteLine("From: " + xMsg.From.Text);
Console.WriteLine("To: " + xMsg.Recipients[0].Text);
Console.WriteLine();
Console.WriteLine(xMsg.Body.Text);
}
try {
}
finally {
xPOP3.Disconnect();
}
}
}
catch (Exception e) {
Console.WriteLine(e.Message);
}
Console.WriteLine("");
Console.WriteLine("Press enter");
Console.ReadLine();
but i edited the attributes according to the req but im geting an error like reference is not their for POP3 class .im using system.web.mail name space
please help with this.
hi to all
with regards,
susa
|
|
|
|
|
hello friends
how can i refer the external files from web.comfig files
coolsweety
|
|
|
|
|
You mean you want to place some settings in an external file, and refer to it from the web.config? If so, you can check out the file[^] attribute of the appSettings element.
|
|
|
|
|
hello you all
what I want is to maintain the session of a user when he register or login with us side by side I want to maintain the session for the cart content
neeru
|
|
|
|
|
U can do that by using Session["UserId"]
Creates and stores userid as a Session
"Aim to go where U have never been B4 and Strive to achieve it"
http://groups.yahoo.com/subscribe/dotnetforfreshers
http://himabinduvejella.blogspot.com
|
|
|
|
|
session["RegNo"]=13;
coolsweety
|
|
|
|
|
yes I know this but I want to maintain it through globle files
|
|
|
|
|
onfiguration Error
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.
Parser Error Message: Access is denied: 'Microsoft.Practices.EnterpriseLibrary.Data'.
Source Error:
Line 196: <add assembly="System.EnterpriseServices, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
Line 197: <add assembly="System.Web.Mobile, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
Line 198: <add assembly="*">
Line 199:
Line 200:
Source File: c:\winnt\microsoft.net\framework\v1.1.4322\Config\machine.config Line: 198
Assembly Load Trace: The following information can be helpful to determine why the assembly 'Microsoft.Practices.EnterpriseLibrary.Data' could not be loaded.
=== Pre-bind state information ===
LOG: DisplayName = Microsoft.Practices.EnterpriseLibrary.Data
(Partial)
LOG: Appbase = file:///c:/inetpub/wwwroot/AutoSys/Procurements/Web
LOG: Initial PrivatePath = bin
Calling assembly : (Unknown).
===
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Post-policy reference: Microsoft.Practices.EnterpriseLibrary.Data
LOG: Attempting download of new URL file:///C:/WINNT/Microsoft.NET/Framework/v1.1.4322/Temporary ASP.NET Files/autosys_procurements_web/14145ce2/887b2a67/Microsoft.Practices.EnterpriseLibrary.Data.DLL.
LOG: Attempting download of new URL file:///C:/WINNT/Microsoft.NET/Framework/v1.1.4322/Temporary ASP.NET Files/autosys_procurements_web/14145ce2/887b2a67/Microsoft.Practices.EnterpriseLibrary.Data/Microsoft.Practices.EnterpriseLibrary.Data.DLL.
LOG: Attempting download of new URL file:///c:/inetpub/wwwroot/AutoSys/Procurements/Web/bin/Microsoft.Practices.EnterpriseLibrary.Data.DLL.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Post-policy reference: Microsoft.Practices.EnterpriseLibrary.Data, Version=1.1.0.0, Culture=neutral, PublicKeyToken=null
This error is accuring most commonly.....Any solutions to rectify it?
"Aim to go where U have never been B4 and Strive to achieve it"
http://groups.yahoo.com/subscribe/dotnetforfreshers
http://himabinduvejella.blogspot.com
|
|
|
|
|
HimaBindu Vejella wrote: Any solutions to rectify it?
You simply copy the assembly Microsoft.Practices.EnterpriseLibrary.Data.dll to the temp folder of your web application:
C:/WINNT/Microsoft.NET/Framework/v1.1.4322/Temporary ASP.NET Files/autosys_procurements_web/14145ce2/887b2a67/
|
|
|
|
|
Hi all,
How to bind the records from sql server tables and display into the HTML table control.
The data should be displayed in the HTML table with all features of datagrid(paging,edit and delete and go to page No).Simply with out using the datagrid.
Pls suggest me with some sample codings.
Thakx
Paul
Paul
|
|
|
|
|
Hi Paul,
The html table control does not support data binding like a data-bound control such as datagrid, datalist ..., so if you want to use the html table, you need to walk through the record collection of the datasource, then build each row (tr) for the table. Also you also need to manage all the built-in features of the datagrid control like paging, sorting ....it seems overhead to you. So I'm curious that why you don't just use the datagrid control.
|
|
|
|
|
Thnak you for your suggession.
But I am trying to do the datagrid functionalty to the html table.
THanks you again
By
Paul
Paul
|
|
|
|
|
Y don't u use DataGrid/List?
"Aim to go where U have never been B4 and Strive to achieve it"
http://groups.yahoo.com/subscribe/dotnetforfreshers
http://himabinduvejella.blogspot.com
|
|
|
|
|
I am tring the code to develop without datagrid/list?
Is it possible to do the same using HTMl Controls??
Paul
|
|
|
|
|
Hi..
I have a DataList that includes in its ItemTemplate an ImageButton which should use FieldNO(a DataItem field in the datasource ) as a QueryString to redirect() to another page:
Response.Redirect("default.aspx?FieldNO="+fieldNO+"&ProjectNO="+projectNO);
But i want this to happen only in a specific situation
(if(searchString!=null) is true) So the DataBinder.Eval() alone wont do what i want.So i used the following code in the method assigned to the OnCommand ImageButton attribute:
string fieldNO;
string argu=e.CommandArgument.ToString();
string[] argss=argu.Split(',');
if(searchString!=null)
{
DataRowView drv=(DataRowView)lProjects.Items[Convert.ToInt32(argss[1])].DataItem;
fieldNO=Convert.ToString(drv["FieldNO"]);
}
Where lProjects is the DataList And the Command Argument of the ImageButton is:
CommandArgument='<%#DataBinder.Eval(Container.DataItem,"ProjectNO")+","+Container.ItemIndex%>'
There is no relation between "ProjectNO" and the problem.The problem exists with the other field "FieldNO"
which i should get it from the datasource of the DataList in a specific condition.
But this code give me the error :
Object reference is not set to an instance.
Sorry if i couldnt explain my problem.
Could any one help?
|
|
|
|
|
+ You can use the ?: operator in the data binding expression to check if you should call the Eval method to populate the command argument.
+ You can wrap your sample code in a method, then simply call it in the data binding expression.
You can see the sample code from here[^].
|
|
|
|
|
These two ideas are exactly what i need.
May you give me code examples for them?...
|
|
|
|
|
You can find the examples from the provided link, and you can easily reuse it for your purpose:
+ Option 1:
<%# (strSearch is not null)? DataBinder.Eval(...):"" %>
+ Option 2:
<%# GetCommandArgument(Container.DataItem) %>
...
you can also define this method in the inline code.
Note: They all are the pseudo code.
|
|
|
|
|
Sorry,i didnt see the last statement in your previous message which was:
"You can see the sample code from here[^]."
Every thing is clear for me now.
Thank you very very much..I wont forget your help.
|
|
|
|
|
TheEagle wrote: Every thing is clear for me now.
Glad to hear you figured it out , good luck to you !
|
|
|
|
|
Hi..
after i build the code in my UserControl it gives me the error:
D:\MyWebApps\EProjects\UserControls\FieldProjectsList.ascx.cs(133): The type or namespace name 'DataBinder' could not be found (are you missing a using directive or an assembly reference?)
It seems to me that the UserControl is different from the WebForm in using the DataBinder class in the code behind page.
Could you help me in this problem?
|
|
|
|