|
What you need to do is save the DataTable in the viewstate and rebind the grid after the save button is clicked.
I have a user control I wrote that does this so here is some sample code. It starts off with an empty grid. Below is the method that creates the initial datatable and stores it in view state.
<br />
void intiGrid()<br />
{<br />
DataTable dt = new DataTable();<br />
DataColumn c = new DataColumn();<br />
c.ColumnName = "ClassCode";<br />
c.DataType = System.Type.GetType("System.String");<br />
dt.Columns.Add(c);<br />
<br />
<br />
c = new DataColumn();<br />
c.ColumnName = "Required";<br />
c.DataType = System.Type.GetType("System.Boolean");<br />
dt.Columns.Add(c);<br />
<br />
c = new DataColumn();<br />
c.ColumnName = "ClassDesc";<br />
c.DataType = System.Type.GetType("System.String");<br />
dt.Columns.Add(c);<br />
DataRow row;<br />
row = dt.NewRow();<br />
row[0] = "New";<br />
row[1] = true;<br />
row[2] = "";<br />
dt.Rows.Add(row);<br />
<br />
DataColumn[] columns = new DataColumn[1];<br />
columns[0] = dt.Columns["ClassCode"];<br />
dt.PrimaryKey = columns;<br />
<br />
this.GVRequiredClassCodes.DataSource = dt;<br />
this.GVRequiredClassCodes.DataBind();<br />
ViewState[this.ClientID.ToString() + "DataTable"] = dt;<br />
}<br />
This next snippet is how I add a new row to the grid.
<br />
DataTable DT = new DataTable();<br />
DT = (DataTable) ViewState[this.ClientID.ToString() + "DataTable"];<br />
DataView DV = new DataView(DT);<br />
DV.Sort = "ClassCode";<br />
<br />
DataRow R;<br />
R = DT.NewRow();<br />
R[0] = sNewClassCode;<br />
R[1] = cb.Checked;<br />
R[2] = classDescription;<br />
DT.Rows.Add(R);<br />
this.GVRequiredClassCodes.DataSource = DV;<br />
this.GVRequiredClassCodes.DataBind();<br />
ViewState[this.ClientID.ToString() + "DataTable"] = DV.ToTable();<br />
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
|
|
|
|
|
I'm writing an asp.net application which will have at least 30 pages that need to be created for editing business objects which I'm porting from a winform app.
They all have a consistent menu so I thought I would put it into a master page and put the different bits in content pages, however from what I can see if I have a save option (for example) on my master page menu, there is no way when a user clicks on it to send that event to the content page for processing.
|
|
|
|
|
You have access to the content page through the ContentPlaceHolder.Page property. From that you could call a Save method on the page.
only two letters away from being an asset
|
|
|
|
|
Yes you can do so. Add an event handler to the page init
Here is the vb.net if you need c# let me know I'll try to convert.
Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init<br />
'FInd the control in your master page and add the event handler<br />
Dim ddl As DropDownList<br />
ddl = CType(Me.Master.FindControl("ddlStates"), DropDownList)<br />
AddHandler ddl.SelectedIndexChanged, AddressOf ddlStates_SelectedIndexChanged<br />
<br />
'ddlState_SelectedIndexChanged <br />
<br />
end sub<br />
<br />
'Method called on post back after user click<br />
Protected Sub ddlStates_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)<br />
'Code to fire from master page event<br />
end sub<br />
-- modified at 12:17 Thursday 27th July, 2006
|
|
|
|
|
Yeah that's it! I extended it into a generic message with object parameter event so I could handle all manner of clicks and various events from the master page.
thanks
|
|
|
|
|
Another option in my humble opinion is that you can define a public event in the Master page, say Save, then any content page would want to handle this event should subscribe it.
|
|
|
|
|
Hi, i finally added a checkbox into my gridview ,great but i still want something to do with
well , i want when i check this checkbox to select the row that this checkbox belong to & i also did it but it just select 1 row not more & i want for each selected or checked checkbox to select its row , so do you have any idea abt that stuff ?
i selected the row with that code :
gridview.rows(i).selectedindex = 0
i selected the first row with that code
when i do a for clause to select mutliple rows the previous row lose the select because
row.selectedindex can select just 1 row
& there is no selected index collection neither a select mode i think
thank you
try to be good if you can't be the best t
|
|
|
|
|
GridView is not multi-select. You can simulate this behavior by changing the background of the rows as needed however.
only two letters away from being an asset
|
|
|
|
|
you mean just illusion isn't it ?
good trick , you win 1-0 i will try it but if i get something i need your help
thank you
try to be good if you can't be the best
|
|
|
|
|
I am making an internal application with very stringent display requests. It will only display properly in IE 5.5 or greater. The end usrs want me to block anyone else's browser so that they are forced to view through IE - how can I set this up with a custom message page explaining that. I am not sure how to proceed - where to put the code etc. . . .
I have to deliver the finished product shortly and really need some assistance,
Thx, T
|
|
|
|
|
If you want to check type of the browser then this you can do with javascript.
Best Regards,
Apurva Kaushal
|
|
|
|
|
But people can turn off javascript so it could never get run.
|
|
|
|
|
Is there not a way to check if the browser is not an IE version and then display a page stating that the requirements require it to be run through IE - this is just an internal application and will not be for public consumption - sorta speak. I would prefer not to use javascript in case it is turned off. I am using some CSS styles that are not viewable in firefox which is one I want to exclude.
Thx, T
|
|
|
|
|
If it will only display in IE 5.5 or greater there is a bigger problem.
A man said to the universe:
"Sir I exist!"
"However," replied the Universe, "The fact has not created in me A sense of obligation."
-- Stephen Crane
|
|
|
|
|
I guess what exactly the need would be that the page will function completely, otherwise the data won't be displayed properly.
Best Regards,
Apurva Kaushal
|
|
|
|
|
Is it possible to store data in database through code.
in asp .net 2.0. i am using textbox to do that it is possible througn prored prodedure. but is there any other way
Please help
Sarbjeet Singh
|
|
|
|
|
Ofcourse it is possible to store data through code(either you can use sqlquery or the stored procedure for that purpose.)
Best Regards,
Apurva Kaushal
|
|
|
|
|
sabby2006 wrote: Is it possible to store data in database through code.
what do you think?
sabby2006 wrote: in asp .net 2.0. i am using textbox to do that
Im pretty sure that a textbox are not able to connect directly to a database.
sabby2006 wrote: but is there any other way
Yes, try asking a meaningful question.
|
|
|
|
|
You might want to have a look around for a few tutorials. Displaying data from a database, changing it and sticking it back in is pretty much what most applications do (most, not all...).
Is it possible to store data in database
And that has to be one of the best thread topics i've ever seen...
|
|
|
|
|
Paddy Boyd wrote: And that has to be one of the best thread topics i've ever seen...
Best Regards,
Apurva Kaushal
|
|
|
|
|
Dispite what everyone else has said it is not possible to store data in a database, that isn't what it is meant for. A database is best used for taking up vast abouts of data storage capacity and employing many unskilled employees known as DBA's in coporate welfare programs until they can be used in more productive capacities, like marketing. ;P
only two letters away from being an asset
|
|
|
|
|
|
Frank Kerrigan wrote: We've managed to keep this secret for 30 years and you've blown it
Best Regards,
Apurva Kaushal
|
|
|
|
|
You made me laugh so high that my project leader came to see what happened lol
And by the way, you can connect directly a TextBox with a datasource in vs2005 at least.
|
|
|
|
|
that was my first day??
i have managed it..
anyway thanks for the laugh
sabby
|
|
|
|