|
How do you define the second column? Is it a bound column or a template column? Basically, you can use the Text property at a specific cell when the column is a bound column. If it is displayed via a control, you need to get reference to the control first, then get the value.
|
|
|
|
|
second column is template colummn in this i am binding like this
<ItemTemplate><br />
<%# DataBinder.Eval(Container.DataItem, "EMAIL")%><br />
</ItemTemplate>
plz tell e
regards
GV Ramana
|
|
|
|
|
Because you are using the data binding expression with the Template column, so the DataBoundLiteralControl is generated in each cell, and you need to cast the control in the Controls collection to this type before you access the Text property:
DataBoundLiteralControl lit = item.Cells[2].Controls[0] as DataBoundLiteralControl;
string value = lit.Text;
|
|
|
|
|
Hello All,
I'm trying to do a page which exports a table to Excel. But a set of statements gets printed on my page, when i try to export it again. The statements are:-
"Server: Microsoft-IIS/5.1 Date: Fri, 21 Jul 2006 11:32:11 GMT X-Powered-By: ASP.NET X-AspNet-Version: 1.1.4322 Content-Disposition: attachment; filename=FileName.xls Cache-Control: private Content-Type: application/octet-stream; charset=utf-8 Content-Length: 3908 "
At first i used "cache" instead of "viewstate".I thought cachewas making problems but all in vain.
Can anyone tell me what the problem is due to?
Thank you.
Regards,
Jeeva
My Code is:-
ViewState["DataTableExportToExcel"] = (DataTable)grdReportResult.DataSource;
private void ExportToExcel()
{
DataSet ds = new DataSet();
DataTable dt = new DataTable();
dt = (DataTable)ViewState["DataTableExportToExcel"];
ds.Tables.Add(dt.Copy());
clsGeneral objclsGeneral = new clsGeneral(); SaveExcel(objclsGeneral.SaveExcelToServer(ds,MapPath("Excell\\FileName.xls")));
//Procedure for exporting data to excel and save it into the server
//Cache.Remove("DataTableExportToExcel");
}
private void SaveExcelToClientMechine(string fileName)
{
System.IO.FileInfo targetFile = new System.IO.FileInfo(fileName);
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=" + targetFile.Name);
Response.AddHeader("Content-Length", targetFile.Length.ToString()) ;
Response.ContentType = "application/octet-stream" ; Response.WriteFile(targetFile.FullName);
}
|
|
|
|
|
+ Using the ViewState to save the DataTable is not a good pratice as it's fit for the primitive stypes.
+ At the end of the SaveExcelToClientMechine method, you may try calling the Response.End method to avoid the html markup of the web page added to the output content.
|
|
|
|
|
Hi,
Thank You so much for the solution.
I was really worried with the HTML markup, when i gave Response.End() it came up all right.
Thanks a lot.
Regards,
jeeva
|
|
|
|
|
i want to compare two dates from two different date picker
Premi
|
|
|
|
|
|
System.DateTime got function name CampareTo
Nav.
-- modified at 8:27 Friday 21st July, 2006
|
|
|
|
|
Try this
DateTime dt = DateTime.Now;
DateTime dt2 = DateTime.Parse("August 15, 2000 10:00:00");
TimeSpan ts = dt-dt2;
using ts object you will get everything.
regards
GV Ramana
|
|
|
|
|
Hi there.
I have a user control and a dynamically created dropdownlist on it. When I select an item in the ddl data is supposed to go into a textbox. The problem is that the SelectedIndexChanged event is only fired the second time I select some item in the ddl.
I think the problem has something to do with the viewstate - it's like the event isn't registered in the viewstate the first time I load the user control??
Here is my code which is in the Page_Load function in the user control:
DropDownList cboBUNK = new DropDownList();
cboBUNK.ID = "m_cboBUNK";
cboBUNK.CssClass = "controlText";
cboBUNK.AutoPostBack = true;
cboBUNK.SelectedIndexChanged += new EventHandler( onCboBUNKSelectedIndexChanged );
....
cboBUNK.DataSource = colBunkanr;
cboBUNK.DataTextField = "BUNK";
cboBUNK.DataValueField = "BUNK";
cboBUNK.DataBind();
cboBUNK.SelectedIndex = 0;
....
m_plhBUNK.Controls.Add( cboBUNK );
|
|
|
|
|
Do you add the user control to the web page dynamically or statically? Basically, the event gets fired based on the comparison of the current selected item persisted in the ViewState with the new posted value. IMO you may not need to set the SelectedIndex in the method. Also you may consider adding the dynamic control in the Page_Init other than the Page_Load.
|
|
|
|
|
Thanx 4 answering.
The user ctrl is added to the web page dynamically. I have 3 radio buttons on the page: Create, Edit and Delete.
> If the user chooses Create the placeholder in the user ctrl will contain a textbox control.
> If the user chooses Edit or Delete the placeholder in the user ctrl will contain a dropdownlist control with all the items he can change/delete. And it's that ddl that wont fire onSelectedIndexChanged event for the first time I pick something in it.
I commented out the set of the SelectedIndex and moved the code which adds the textbox/dropdownlist to the placeholder in the OnInit function but it made no difference
Other suggestions?
P.S. IMO?
|
|
|
|
|
I guess that you dynamically add the user control to the web page on postback after the ViewState is loaded. IMO, you can do that in a simpler way:
+ In the user control, you can simply declare two controls textbox and dropdownlist, and depending on which action is taken by the user, you can make the textbox/dropdownlist visible/invisible.
+ In the web page, if you dynamically load the web user control, you can add it in the Page_Init, and depending on which radio button is selected, you can set a public property in the web user control which in turn controls the visibility of the TextBox and dropdownlist. Even simpler, you can declare the web user control right in the web page instead of dynamically loading it.
|
|
|
|
|
+ In the user control, you can simply declare two controls textbox and dropdownlist, and depending on which action is taken by the user, you can make the textbox/dropdownlist visible/invisible.
> Yeah, I thought of that... changed the code but it doesn't solve the problem - for the first 2 times the first item in the ddl remains selected (the SelectedItemChanged isn't called the first time the user picks another item).
+ In the web page, if you dynamically load the web user control, you can add it in the Page_Init, and depending on which radio button is selected, you can set a public property in the web user control which in turn controls the visibility of the TextBox and dropdownlist.
> Tried that one but then if I select something different in the ddl which is in it the first item is always selected.
+ Even simpler, you can declare the web user control right in the web page instead of dynamically loading it.
> No can do. I have about 50 user controls to choose from which depends on a dropdownlist (beside the radio buttons).. and each of the user controls is dependant on the radio buttons I mentioned above.
I guess that you dynamically add the user control to the web page on postback after the ViewState is loaded. IMO, you can do that in a simpler way:
> I have an event handler for each of the three radio buttons and in them I load the right user control and they determine if the textbox or ddl is visible or not. According to .NET event-handling code is always run after the viewstate is loaded, so yeah.
The problem remains unresolved... but thanx for answering..
|
|
|
|
|
Do you set a value for the ID of the dynamic user control? If you don't, you'll need to do because in the first time you load and add the dynamic control in the event handler of the radio buttons, and the control is readded on postback in another event which should occurs early in the control life cycle in order for the postback event (SelectedIndexChanged) work. So if you don't specify an id for the control, the ASP.NET will automatically generate the id for the control. And as a result of that, the control has different id values, and the ASP.NET cannot process the posted data. From the second time on, the control is always added in an event until you select a new action from the radio buttons, so the auto-generated id of the user control is the same, the ASP.NET can process the postback data and the SelectedIndexChanged event gets fired. Below is a simple example to demonstrate what you might want to do, the sample code consists of the web user control and the testing web page.
--------Web User Control sample code -----------
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="WebUserControl1.ascx.cs" Inherits="SampleWeb1.WebUserControl1" %>
<asp:TextBox ID="TextBox1" runat="server" Visible="true"></asp:TextBox>
<br />
<asp:DropDownList ID="DropDownList1" runat="server" Visible="false" AutoPostBack="True" On_SelectedIndexChanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem Text="Item1" Value="Item1" Selected="True"></asp:ListItem>
<asp:ListItem Text="Item2" Value="Item2" ></asp:ListItem>
<asp:ListItem Text="Item3" Value="Item3" ></asp:ListItem>
<asp:ListItem Text="Item4" Value="Item4" ></asp:ListItem>
</asp:DropDownList>
namespace SampleWeb1
{
public partial class WebUserControl1 : UserControl
{
public string Action
{
get
{
if (ViewState["Action"] == null)
ViewState["Action"] = "Create";
return (string)ViewState["Action"];
}
set
{
ViewState["Action"] = value;
SetControlVisibility();
}
}
protected void Page_Load(object sender, EventArgs e)
{
}
protected override void LoadViewState(object savedState)
{
base.LoadViewState(savedState);
SetControlVisibility();
}
private void SetControlVisibility()
{
TextBox1.Visible = (Action == "Create");
DropDownList1.Visible = !TextBox1.Visible;
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
Response.Write(string.Format("New selected value: {0}<br/>", DropDownList1.SelectedValue));
}
}
}
--------Testing web page -------------
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="SampleWeb1._Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:RadioButtonList runat="server" ID="rdoActionList" AutoPostBack="True" On_SelectedIndexChanged="rdoActionList_SelectedIndexChanged">
<asp:ListItem Text="Create" Value="Create"></asp:ListItem>
<asp:ListItem Text="Edit" Value="Edit"></asp:ListItem>
<asp:ListItem Text="Delete" Value="Delete"></asp:ListItem>
</asp:RadioButtonList>
<asp:PlaceHolder runat="server" ID="PlaceHolder1">
</asp:PlaceHolder>
</form>
</body>
</html>
namespace SampleWeb1
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
private string CurrentControlUrl
{
get
{
if (ViewState["CurrentControlUrl"] == null)
return string.Empty;
return (string)ViewState["CurrentControlUrl"];
}
set
{
ViewState["CurrentControlUrl"] = value;
}
}
protected override void LoadViewState(object savedState)
{
base.LoadViewState(savedState);
if (!string.IsNullOrEmpty(CurrentControlUrl))
{
WebUserControl1 control = (WebUserControl1)LoadControl(CurrentControlUrl);
control.ID = "WebUserControl1";
PlaceHolder1.Controls.Add(control);
}
}
protected void rdoActionList_SelectedIndexChanged(object sender, EventArgs e)
{
//Persist the dynamic user control to reload it on postback.
CurrentControlUrl = "WebUserControl1.ascx";
WebUserControl1 control = (WebUserControl1)LoadControl(CurrentControlUrl);
//Explicitly specify the id of the control.
control.ID = "WebUserControl1";
PlaceHolder1.Controls.Clear();
PlaceHolder1.Controls.Add(control);
control.Action = rdoActionList.SelectedValue;
}
}
} Last modified: Thursday, July 27, 2006 12:16:05 AM --
|
|
|
|
|
Halleluja!
The ID did the trick - just had to add it to the user ctrl whenever I loaded it.
Thank you very very very much for the help
|
|
|
|
|
hi
i'm facing a weird situation..i hav uploaded all my project on the client server.
but RequirdField Validator,Compare Validator and RegularExperssion is not working on server..but they are working fine on local host.
how is it possible and what to do slove it.
on server no validator control is working
thanx
|
|
|
|
|
Try this....
upload a copy of WebUIValidation.js to a directory
within your application.
Add the following line to your web.config
<webControls clientScriptsLocation="YourApp/YourScriptsDirectory/" />
hope this work
Nav.
|
|
|
|
|
I am using .NET 2.0 C#. How do I sort the data in a gridiew.
I constructed the data manually. Is there any sample or link?
thanks in advance. Much appreciated.
|
|
|
|
|
You need to sort it before binding to the grid. How to sort it depends on what structure it is in.
|
|
|
|
|
|
Good Day !
Did anyone know how to pass a whole data from one .aspx page to another .aspx page? Can anyone give me a sample code or solution. Thanks..
Best Regards,
Pei Sun
|
|
|
|
|
You can paas the data from one page to another page in multiple way. One simple way is to pass it through querystring. Here your data will be there with the URL and in the next page you can retrive the data from the querystring.
Best Regards,
Apurva Kaushal
|
|
|
|
|
can you give me sample code as a reference?
Best Regards,
Pei Sun
|
|
|
|