|
Hi, Thanks for helping.
I read somewhere that we specifically needed to rebind on every page load so that the dynamically created control can repopulate its viewstate. If I don't do the rebind on page_load, the GridViewRow/Textbox will disappear upon postback.
I tried bind once and rebind after a postback but still the text box is empty.
can you elaborate on this point?
What you need to do is save the text entered in the grid and recreate the row.
Do you mean store text in hidden field or viewstate and manually repopulate the textbox when binding?
Thank You
Jim
silverfox_1188
|
|
|
|
|
One possible solution...
When your page post's back find the row
foreach (GriedViewRow row in gridview.rows)
{
//find your row via some key or id that you add to the row
Textbox txt = (TextBox) row.findcontrol("txtbox1");
viewstate["txtbox1Value"] = txt.text;
}
Now when you go bind the grid again you will have the value
TableCell objTableCell = new TableCell();
objTableCell.ID = "firstCell";
//jTableRow.Cells.Add(objTableCell);
objTableRow.Controls.Add(objTableCell);
TextBox objTB = new TextBox();
//Add the following
objTB.text = viewstate["txtbox1Value"].ToString();
how vital enterprise application are for proactive organizations leveraging collective synergy to think outside the box and formulate their key objectives into a win-win game plan with a quality-driven approach that focuses on empowering key players to drive-up their core competencies and increase expectations with an all-around initiative to drive up the bottom-line. But of course, that's all a "high level" overview of things
--thedailywtf 3/21/06
|
|
|
|
|
Hi, Thank You again.
I try your suggestion and it works great. We always do grid databind on Page_Load, then onCommand button event, we store the textbox values into the viewstate, after that the sqldatasource automatically rebinds after prerender, this time we repopulate the values from viewstate.
In your oppinon, is it worth the performance hit to create dynamic controls and having to rebind on every page_load and after prerender? We could have simply placed the 2 text boxes outside of the gridview instead of adding it to the grid dynamically. It would have been easier to code but my client insisted on having them inside. What do you recommend?
thanks again,
Jim
silverfox_1188
|
|
|
|
|
actually you shouldn't rebind.
store the table inside your view state
and on page load rebind to the table from viewstate.
theres no need to cache specific row data
private DataTable myTable = new DateTable(...);
pageLoad
if(!PostBack)
myTable = ... get the data from your biz layer ...;
ViewState["MyTable"] = myTable;
set data grid
else
DataGrid.DataSource = ViewState["MyTable"] as DataTable;
rebind
The reason why your changes are not shown is this.
First you create a table which has a unique identifier attached to it.
So you make changes and repost
When you get a new data table you have a different unique identifier which .net will wipe any changes and events tied to that source
You need to rebind every time, but use the table from the ViewState.
Also if you need to add format additional controls use the ItemCreated event to format them.
If you data bind them there, you shouldn't have a need to hack the form and make life difficult
Nick
--------------------------------------------------------
1 line of code equals many bugs. So don't write any!!
My mad coder blog
|
|
|
|
|
Thank You everyone for your valuable insights!
silverfox_1188
|
|
|
|
|
Hi Everyone,
I am working on this project in ASP.NET and I used this code, and I wanted to to output as currency which SHOULD work, but it won't.
<%# DataBinder.Eval(Container.DataItem, "invoicetotal","{0:c}") %>
Is there something that I am doing wrong, no commas or dollar signs show up when I use that for some reason.
Thanks,
The Major Rager
|
|
|
|
|
Put this DataFormatString="{0:C}" in the tag but outside of the databinder.
how vital enterprise application are for proactive organizations leveraging collective synergy to think outside the box and formulate their key objectives into a win-win game plan with a quality-driven approach that focuses on empowering key players to drive-up their core competencies and increase expectations with an all-around initiative to drive up the bottom-line. But of course, that's all a "high level" overview of things
--thedailywtf 3/21/06
|
|
|
|
|
Thanks for your help!
Sincerely,
The Major Rager
|
|
|
|
|
Hi,
Cache is used to store frequently used data and read only data.
Application state is to provide a share point for accessing global, read-only data in an application.
Then What is the difference between Application and Cache.
Which is best in which scenario.
Thanks in advance.
|
|
|
|
|
The difference is that items in the cache will be dropped when the memory resources are better used for something else. If you store too much in the Application object, the server will run out of free memory and start swapping virtual memory to disk, which will make the server very slow.
---
b { font-weight: normal; }
|
|
|
|
|
HI all
I am trying to Redirecting the page to flash file from "page1.aspx" page
Response.Redirect("Play.swf")
But the flash file is not working
But after refreshing the Play.swf page is working
Can any one tell me what is the error
THX
asdfasdfasdfasdfasdfasdfasdfasdfasdfasdf
|
|
|
|
|
I dont know why... But why dont you just redirect to an aspx page as normal, and you can embed the swf file in there ...
<< >>
|
|
|
|
|
Hi Everyone,
I am working on a project where I am going to need to make a few charts and graphs using Excel. I do not have the Office tools for Visual Studio and I was wondering what was the best way to do this. The graphs also should not be just an image, but interactive where I can hover or click one of the bars on the bar graph and it should tell me something. If anyone can give me a few ideas I would truly appreciate it.
Thanks
|
|
|
|
|
Because you are using chart in an ASP.NET application, I think you may consider using a third party component like Dundas Chart[^].
|
|
|
|
|
Can any one have idea, how to build one asp.net application via anotherone asp.net application?. Example: BuildApp.aspx contains one TexBox and Button, if enter a filename to be build in the Textbox and click the Button, it should build the application as we doing thru vs.net IDE build menu.
Thanks in Advance
|
|
|
|
|
you could probable use ShellExecute or similar to spawn MSBuild with the correct command line
"Now I guess I'll sit back and watch people misinterpret what I just said......"
Christian Graus At The Soapbox
|
|
|
|
|
Thanks for your tips. It would be very helpful to me if u show me some code or link which explains this ShellExecutable technique.;)
|
|
|
|
|
ShellExecute is a WIN32 API function - not sure how you'd go about accessing it from .NET tbh - haven't used it for a while! Think there's something in System.Diagnostics for running a process - MSDN will help
"Now I guess I'll sit back and watch people misinterpret what I just said......"
Christian Graus At The Soapbox
|
|
|
|
|
|
Use the codeDom namespace to create code on the fly and compile it
--------------------------------------------------------
1 line of code equals many bugs. So don't write any!!
My mad coder blog
|
|
|
|
|
Hi Everybody!!!
I fill a DataGrid with a SQLServer Database, so far so good, but because the name of the fields were thought for internal development work, they're not friendly, so I have to change them, I do that in the ItemDataBound.
But here comes the problem: if I change the headers text, the SortCommand Event doesn't work. what I'm doing wrong? is there another way to change the headers text? or should I bind the grid in another way?
Thanks for your time.
Greetings from Mexico.
|
|
|
|
|
Actually the easiest thing to do would be to change the columns names in the query. Like this.
select column1 as NewColomnName from yourTable
how vital enterprise application are for proactive organizations leveraging collective synergy to think outside the box and formulate their key objectives into a win-win game plan with a quality-driven approach that focuses on empowering key players to drive-up their core competencies and increase expectations with an all-around initiative to drive up the bottom-line. But of course, that's all a "high level" overview of things
--thedailywtf 3/21/06
|
|
|
|
|
Thanks ToddHileHoffer!!!
I did what you told me and it worked!!!
Now I'm just wondering how works the relation between the headers and that event...
|
|
|
|
|
white.thief wrote: if I change the headers text, the SortCommand Event doesn't work.
You can change the HeaderText with a friendly name, but you can keep the dev name in the SortExpression property of the column?
|
|
|
|
|
Hi minhpc_bk!
To your cuestion: No, I can´t. But, but with the advice of ToddHileHoffer all that I had to do was a little function that could make the traslation of the friendly names to the dev names, and that was it.
Greetings.
|
|
|
|