|
Try starting with a Google search on "asp.net popup menu". I found some good articles that should give you some ideas.
|
|
|
|
|
Hi all,
I have a requirement to add a checkbox to a datagrid, but on some rows.
If I am asking something that's already covered elsewhere, I apologise.
I have tried a couple of things, but not go
Please find below the code of what I am trying to do (flames welcomed ).
I would greatly appreciate feedback on this.
<br />
<br />
Private Function fnPopulateDataGrid()<br />
Try<br />
' Define a dataset the is used to store the retrieved data from SQL<br />
' This dataset is going to be used to hold multiple result sets.<br />
' These result sets are:<br />
' * Country<br />
' * Region<br />
' * Dates - From the diary<br />
' * Merchandisers<br />
' * Account details and Merchandiser claim details<br />
Dim oDS As DataSet<br />
'<br />
' This is the data table used to 'massage' the result sets for output.<br />
' It is our generic 'container' used for the purpose of our results which<br />
' we WANT to have programatic control over.<br />
Dim oTable As DataTable = New DataTable("RESULTS")<br />
'<br />
' Set up columns in the results table (oTable)<br />
' Note how we actually define the column header, and the data type the column will<br />
' be utilising. We could have avoided this, but for type save conversions<br />
' it is much more safer to have explicite types (as we do in database fields for tables).<br />
oTable.Columns.Add("Country", GetType(System.String))<br />
oTable.Columns.Add("Region", GetType(System.String))<br />
oTable.Columns.Add("Diary Date", GetType(System.String))<br />
oTable.Columns.Add("Merchandiser", GetType(System.String))<br />
oTable.Columns.Add("Customer", GetType(System.String))<br />
oTable.Columns.Add("Claim Time", GetType(System.String))<br />
oTable.Columns.Add("Claim Kms", GetType(System.Int32))<br />
oTable.Columns.Add("Approved", GetType(System.Web.UI.WebControls.CheckBox))<br />
'<br />
' New instance of a check box for the approve facilitation.<br />
Dim oCheckBox As CheckBox = New CheckBox<br />
oCheckBox.Visible = True<br />
oCheckBox.Enabled = True<br />
'<br />
' Here is defined each table to be used to map to each result set<br />
' obtained from the data set<br />
Dim oCountryTable As DataTable = New DataTable("Countries")<br />
Dim oRegionTable As DataTable = New DataTable("Regions")<br />
Dim oDiaryDateTable As DataTable = New DataTable("DiaryDates")<br />
Dim oMerchandiserTable As DataTable = New DataTable("Merchandisers")<br />
Dim oCustomerTable As DataTable = New DataTable("Customers")<br />
'<br />
' And now we define our rows to be added into out data table for output<br />
' oRow is a 'generic' row used specifically for the output data table.<br />
' We use this row to populate each column (as defined above).<br />
Dim oRow As DataRow<br />
'<br />
' And now a row defined for each data table in our data set.<br />
' We want to have a data row defined so we can access the details, form<br />
' relationships and use for processing<br />
Dim oCountryRow As DataRow<br />
Dim oRegionRow As DataRow<br />
Dim oDiaryDateRow As DataRow<br />
Dim oMerchandiserRow As DataRow<br />
Dim oCustomerRow As DataRow<br />
'<br />
' The function called returns a DataSet<br />
' Lets call our business facade method to get us our mechandisers passing no parameters <br />
' at this point.<br />
' The parameters are obtained from within the function.<br />
' We eventually call sp_getMerchandiserClaimDetails stored procedure.<br />
' Note: We are using the Microsoft Data Access Blocks, which is a part of the Microsoft Enterprise Blocks<br />
' (Just so that it is a bit more repeatable, and robust - like java - haha).<br />
oDS = fnGetMerchHierData()<br />
'<br />
' Now we have our data set with multiple result sets, we want to store these results into<br />
' a table of their own.<br />
' In this case we want to have a country, Region, Date, Merchandiser and Customer table<br />
' so we can use more efficiently and cleanly going forward.<br />
' We can address each result set in the data set by referencing the index (as we haven't named them<br />
' for efficiency purposes. We name 'things' going forward for readability and supportability<br />
' purposes.<br />
' Once we have our addressed result set from our data set populated from the business facade,<br />
' we explicitely set it to our prior defined data tables so we can use them in an<br />
' object-relational fasshion (as per below).<br />
oCountryTable = oDS.Tables(0)<br />
oRegionTable = oDS.Tables(1)<br />
oDiaryDateTable = oDS.Tables(2)<br />
oMerchandiserTable = oDS.Tables(3)<br />
oCustomerTable = oDS.Tables(4)<br />
'<br />
' Now we define our relationships between our data tables.<br />
' Note how we define it to our Data Set, as it is the primary container for all the tables.<br />
' Note: a data set is an in memory data base (IMDB).<br />
' Note: We hare using 3 parameters in the .Relations.Add method as opposed to 4.<br />
' The 4th parameter is used to overide whether or not a constraint is formed or not.<br />
' By default (by excluding this parameter) it forces a constraint.<br />
' This has been intentionally designed this way to ensure we do not violate any<br />
' integrity rules, and also ensure we have correct data as we populate our data table.<br />
' Note: Because of the way we are forming these relation ships, we actually creating<br />
' Parent -> Child -> Sub-Child -> Sub-Sub-Child -> Sub-Sub-Sub-Child relations<br />
' in the following fasion:<br />
' Country -> Region -> Dates -> Merchandisers -> Accounts serviced and claim details<br />
' First establish a relationship between Country as our parent to child records, Regions.<br />
oDS.Relations.Add("Regions", oCountryTable.Columns("CountryID"), oRegionTable.Columns("CountryID"))<br />
'<br />
' Next, we define a relationship between Region as the parent to child records, Dates.<br />
oDS.Relations.Add("DiaryDates", oRegionTable.Columns("RegionID"), oDiaryDateTable.Columns("RegionID"))<br />
' Next, we define a relationship between Dates as the parent to chile records, Merchandisers.<br />
'oDS.Relations.Add("Merchandisers", oDiaryDateTable.Columns("DiaryDate"), oMerchandiserTable.Columns("DiaryDate"))<br />
oDS.Relations.Add("Merchandisers", oDiaryDateTable.Columns("DiaryRegionID"), oMerchandiserTable.Columns("DiaryRegionID"))<br />
' Finaly, we establish a relationship between Merchandisers as the parent to the child records, the accounts serviced.<br />
oDS.Relations.Add("Customers", oMerchandiserTable.Columns("DiaryID"), oCustomerTable.Columns("DiaryID"))<br />
'<br />
'<br />
' Now the hard yakka. Lets go through our data tables (related).<br />
' Because we now have a relationional IMDB, we can access this in a programatic fashion.<br />
' We start off with our 'base' table, being Countries, and access the child, sub-child records<br />
' as defined in our relationships above.<br />
' Note: For each 'dimension' specified we generically add a row to our data table (oRow within Table)<br />
' so we can accordingly add the dimension specific (column) to the row to represent the detail<br />
' required in a hierarchical fashion. So, in essence we have grouped data into their logical<br />
' relation.<br />
' We cascade 'down' the relations in the order of parent -> child definitions.<br />
' This is: Country -> Region -> Dates -> Merchandisers -> Accounts serviced and claim details.<br />
' Note : To obtain the child details from the parent form, we use the .GetChildRows(SubstituteTableNameHere).<br />
' This utilises the data tables defined above, the relations formed above them, and<br />
' we can be sure that the integrity is maintained by the rules upon forming the relations.<br />
For Each oCountryRow In oCountryTable.Rows<br />
oRow = oTable.NewRow()<br />
oRow("Country") = oCountryRow("Country")<br />
oTable.Rows.Add(oRow)<br />
For Each oRegionRow In oCountryRow.GetChildRows("Regions")<br />
oRow = oTable.NewRow()<br />
oRow("Region") = oRegionRow("Region")<br />
oTable.Rows.Add(oRow)<br />
For Each oDiaryDateRow In oRegionRow.GetChildRows("DiaryDates")<br />
oRow = oTable.NewRow()<br />
oRow("Diary Date") = oDiaryDateRow("DiaryDate")<br />
oTable.Rows.Add(oRow)<br />
For Each oMerchandiserRow In oDiaryDateRow.GetChildRows("Merchandisers")<br />
oRow = oTable.NewRow()<br />
oRow("Merchandiser") = oMerchandiserRow("Merchandiser")<br />
oTable.Rows.Add(oRow)<br />
For Each oCustomerRow In oMerchandiserRow.GetChildRows("Customers")<br />
oRow = oTable.NewRow()<br />
oRow("Customer") = oCustomerRow("Customer")<br />
oRow("Claim Time") = oCustomerRow("ClaimTime")<br />
oRow("Claim Kms") = oCustomerRow("ClaimKms")<br />
'<br />
' Add the Approved value as a checkbox control<br />
If oCustomerRow("Approved").GetType.ToString = "System.DBNull" Then<br />
oCheckBox.Checked = False<br />
Else<br />
oCheckBox.Checked = CBool(oCustomerRow("Approved"))<br />
End If<br />
oRow("Approved") = oCheckBox<br />
'<br />
oTable.Rows.Add(oRow)<br />
Next<br />
Next<br />
Next<br />
Next<br />
Next<br />
'<br />
' We now want to add our data table (oTable) to our result set (oDS) just incase we want to<br />
' further process any details within our data set (oDS).<br />
' so, we have our original result sets from our busines facade, and our 'processed'<br />
' data table (oTable) from this function.<br />
oDS.Tables.Add(oTable)<br />
'<br />
' We now define to our data grid (dgMerchandiserClaimData) the source of where it will be<br />
' getting it's data to present.<br />
' Because we have gone to the effort of 'processing' and generating our own data table (oTable),<br />
' we want to actually use this explicitly.<br />
' We have opted to specify .DefaultView which gets any defined customized<br />
' view of the table which may include a filtered view, or a cursor position. We haven't defined<br />
' any of these customisations for our purposed, but it gives us the ability to do so incase we do.<br />
dgMerchandiserClaimData.DataSource = oTable.DefaultView<br />
'<br />
' Add our checkbox to the grid :S<br />
'dgMerchandiserClaimData.Columns.Add(oApprovedColumn)<br />
'<br />
' Now we actually form the bind from the defined data source to the grid.<br />
dgMerchandiserClaimData.DataBind()<br />
<br />
Catch ex As Exception<br />
Throw New Exception(ex.Message, ex)<br />
End Try<br />
End Function<br />
<br />
Thank you and Kind Regards,
John Zantey
|
|
|
|
|
That's a lot of code to read through...
could you not just add a checkbox column to your datagrid and then on the item databound event set it to not visible for those items where you don't want it to display?
|
|
|
|
|
You have to add a template column in which you have to place a checkbox.
Now at runtime you have to make a loop on all datagrid rows. Now in loop find control i.e. checkbox and make the checkbox visible property to false where you donot want to show the check box.
Do good and have good.
|
|
|
|
|
I have a web application which uses oracle database. Below is the minimum code which explains how I am accessing the data.
At a time the application working fine and I can access and do everything with database. Some other time database server is down for scheduled maintenance. If I try to run the application at this point of time it will raise err "ORA-12154: TNS:could not resolve service name"
(I'm catching this exception and displaying a custom error message to users). After some hours the database server is up an running.
Now if I run the application it should behave normal and give database access. But it dose not, and continue to give the same ORA-12154" error.
In such case I have to reset IIS to make the application work normal. So the question is how to avoid re-occurring Err "ORA-12154".
private string get_name()
{
string name = "no name";
string conn_str = "Provider=MSDAORA.1;Persist Security Info=True;Data Source=test;User ID=test;Password=test";
OleDbConnection db_conn = new OleDbConnection(conn_str);
db_conn.Open();
string str_sql = "select name_complete from emp_master " +
"where emp_no = '" + TextBox1.Text + "'";
OleDbCommand db_cmd = new OleDbCommand(str_sql, db_conn);
OleDbDataReader db_reader = db_cmd.ExecuteReader();
while (db_reader.Read())
{
name = db_reader[0].ToString();
}
db_reader.Close();
db_conn.Close();
return name;
}
CA Keer.
|
|
|
|
|
Your issue might be oracle specific, however I've experienced a somewhat similar problem due to connection pooling in Firebird and MS SQL server. You might want to try emptying the connection pool forcefully when you get that exception.
|
|
|
|
|
also not calling Dispose on the connection object will not pool the connection
--------------------------------------------------------
1 line of code equals many bugs. So don't write any!!
My mad coder blog
|
|
|
|
|
I tried your suggession as below but dose not solve the issue. The issue is not related to Oracle i guess. Because everything is same and I only have to reset IIS. Thats restores the database access to normal.
try
{
dbConn.Open();
}
catch(Exception ex)
{
dbConn.Dispose();
}
CA Keer.
|
|
|
|
|
cs8569 wrote: try
{
dbConn.Open();
}
catch(Exception ex)
{
dbConn.Dispose();
}
should be:
{
dbConn.Open();
}
catch(Exception ex)
{ }
dbConn.Dispose();
--------------------------------------------------------
1 line of code equals many bugs. So don't write any!!
My mad coder blog
|
|
|
|
|
As per MSDN Note "To deploy high-performance applications, you need to use connection pooling. When you use the .NET Framework Data Provider for OLE DB, you do not need to enable connection pooling because the provider manages this automatically."
The connection will establish if "db_conn.Open();" is successfull. (The Err hits at this line) If its not successful that means there is no connection and I dont need to close or dispose it?
However I still tried what you have suggested. I also tried using OleDbDataAdapter believing that it will manage the connection its own and I dont need to take care of closing or disposing the connection. But both approches did not solve the problem.
CA Keer.
|
|
|
|
|
i use the following in web config file
<appsetting>
<add key="AuthLogName" value="12345"/>
<add key="AuthPwd" value="56789>
</;appsetting>
and in cs file, i access the above credentials using following
object.Proxy.Credentials = new NetworkCredential(app.GetValue("AccUName", Type.GetType("System.String")).ToString(), app.GetValue("AccPwd", Type.GetType("System.String")).ToString(), app.GetValue("AccDomain", Type.GetType("System.String")).ToString());
i wana avoid the code in cs fine and directly give it under web config file
how do i do
thanks
jiny
|
|
|
|
|
I think I can see why no one has responded yet to this post. I would like to help, but it is not clear based on the post what you are interested in accomplishing that is different than what you already have.
|
|
|
|
|
Hi all,
i want to add additional functionality in my DataGrid that when ever user click on any area of the DataGrid's row it shoud be highlighted and on double Clicking on the row would redirect the user to specific URl.
any help would be greatly appriciated.
Regards,
T a H i r
|
|
|
|
|
|
THanks Mike your links helped me alot.
|
|
|
|
|
Hi all,
Pls anybody can help me to build and maintain the Shopping Cart in asp.net 2.0 using C#?.
I didnt find any useful article for that.
Thanks in advance.
Regards,
Jay
|
|
|
|
|
Lucky for you I implemented sth similar recently.
What I did was to use Arraylists (They are very effective for scenarios where removal and insertion of data is integral).
You can add data into these arraylists appropriately on an event and consequently remove data. Then you can add a listbox to the page and for it's items add for example: (product name + no purchased + total price) i.e the concatenation of the 3 values into the listbox's item's collection. So if someone clicks on Add Item, It adds all items to their arraylists, and also to the listbox.
Let the listbox's selected index be the index for your arraylist when removing items from them
e.g productArraylist.RemoveAt(listbox1.SelectedIndex)
That's just about it.
You can go ahead and store your arraylists in Session Variables. If you want to add to a database, use a foreach to run through each arralist and call a method, passing it the items in the arraylist as it's data.
e.g: AddQuery(productArrayList.Items[i].ToString(), quanArrayList.Items[i].ToString(), etc)
So the AddQuery takes all the parameters and performs the database operations. Remember to make that method static and place it in the AppCode folder.
That's all the basic stuff you need to know about doing a shopping cart.
The rest is up to you.
Live in fragments no longer. Only connect.
|
|
|
|
|
Thanks 4 ur guidance.
I ve got the basic idea about building the Shopping Cart.
Happy programming...
Regars,
Jay
|
|
|
|
|
Here is a challenging question, as I have not found any suitable information on this after two days of searching:
Background:
I have a custom Business Class library that includes custom objects with nullable int and DateTime properties. In order to update this data, I have created a FormView control bound to an ObjectDataSource that retrieves a generic List collection of my business objects. The reflection that is intrinsically called by the FormView/ObjectDataSource combination dutifully builds my basic Select, Update, and Insert templates. Now, when you edit the various (TextBoxes by default) input fields and then call the Update method referenced in the ODS (ObjectDataSource), the ODS attempts to convert the data contained in the input fields to the corresponding Type of the property bound to said input field. This is where we run into our little problem...
Even though I have a nullable Integer property type (let's call it int? ClassNumber), if the corresponding TextBox is empty (since it's not required), an exception is thrown by the ODS since it tries to convert an empty string value to an integer value before trying to set the object's Property. Hah! If ODS was able to determine that the integer is in fact nullable, it should pass in a null value instead! But alas, it throws a System.IndexOutOfRangeException: "Index was outside the bounds of the array" error. And further down the stack: "Exception: is not a valid value for Int32". Hmmm. Since this is a FormView control, we don't have the ability to use a BoundField control with 2 very useful properties: NullDisplayText and ConvertEmptyStringToNull. It would be nice to tell ODS to enable sending null values from any control we want. I wonder, can a TextBox control be extended to implement those two values? But I digress...
I suppose I could use the UpdateButton_Click event handler to evaluate the TextBox (or whatever) input controls in question and if the value is empty, input a default value (like zero), but this has Business Rule implications as well as invalidating the reason for using nullable types in the first place. Since I am creating my global Class Library as flexible as possible for use in many different web/desktop/whatever applications, I don't want to start implementing a hundred specialized case handlers, like if the int? value == 0, set it to null, because what if in other cases, 0 (or -1 for that matter) is perfectly acceptable? Once again, the reason for nullable types. Since I know that other developers may very well use a FormView with an ObjectDataSource, it might be handy to provide a custom (extended) FormView, textbox, or ODS control that can handle null values. Unless I am totally missing something else. DetailsView isn't template-able for Updating and I don't like updating from a GridView if there are a lot of fields. DataView is a pain, too.
Does anyone have any better suggestions?
Thanks ,
Joel
|
|
|
|
|
Sorry I didnt read the whole thing but lunch is here.
I havent used FormView much but cant you just modify the ItemDataBound event to control the nulls?
--------------------------------------------------------
1 line of code equals many bugs. So don't write any!!
My mad coder blog
|
|
|
|
|
No. You can set the value of the form field in it's Data Binding event to some value if it is empty (such as 0 or -1) then handle that scenario on the business class such as set it to null if it is <= 0, but that only works for instances where the value has to be greater than 0.
The Updating event on the Object data source is too late in the hierarchy, as well as every other event where you could possibly send a null value to the data binder. It seems as though the ODS instructs the FormView control as to the type it needs to convert the input fields' values to since all the conversion is attempted before the data is bound to the ODS.
|
|
|
|
|
Does this help?
Data controls support a variety of ways to handle null or missing data. To begin with, the GridView, FormView, and DetailsView all support an EmptyDataText or EmptyDataTemplate property that you can use to specify a rendering for the control when the data source returns no rows of data. Only one of EmptyDataText and EmptyData needs to be set (EmptyDataTemplate overrides when both are set). You can also specify a ConvertEmptyStringToNull property on BoundFields or data source parameter objects to specify that String.Empty values posted from the client should be converted to null before invoking the associated data source operation. ObjectDataSource also supports a ConvertNullToDbNull property that can be set to true when the associated method expects DbNull parameters instead of null (the TableAdapter classes in a Visual Studio DataSet have this requirement). You can also specify a NullDisplayText property on BoundField to specify a value for the field to display when the field value from the data source is returned as null. If this value is not changed during edit mode, the value will roundtrip as null back to the data source during an Update operation. Lastly, you can also specify a DefaultValue property on data source parameters to specify a default value for the parameter when the parameter value passed is null. These properties can a chaining effect, for example if both ConvertEmptyStringToNull and DefaultValue are set, a String.Empty value will first be converted to null and subsequently to the default value.
But since your objects receieve null they would be defines as object. and you would think that it would just create the object type and be okay.
Hope that helps,
Nick
--------------------------------------------------------
1 line of code equals many bugs. So don't write any!!
My mad coder blog
|
|
|
|
|
Nick,
I appreciate your comments, however, since this is a FormView control, I cannot use BoundFields, which are the ones with the helpful EmptyDataText and ConvertEmptyStringToNull properties. These properties are unavailable on TextBox, FormView, and ObjectDataSource controls. BoundFields can only be used in GridView, DetailView, and DataList controls. Since no null values are being sent up to my object (using two-way binding), I have to handle empty text boxes differently. My properties include String, nullable DateTime, nullable Integer, and nullable Decimal types. Therefore, DBNull is irrelevant.
Wait a minute! I've got an idea! I'm going to try setting the ODS flag, ConvertNullToDBNull, to true and see if it sends empty text boxes as DBNull, since it won't send null. If so, I can simply catch DBNulls in my properties' set property bag and just handle it as a null value from there!
I'll let you know if it works.
Thanks,
Joel
|
|
|
|
|
yeah. I want to test this out also. It seems ignorant to have an object source control and not send null.
-- modified at 17:20 Friday 28th July, 2006
--------------------------------------------------------
1 line of code equals many bugs. So don't write any!!
My mad coder blog
|
|
|
|
|
And I would also think that you can set the UpdateMethod to call a custom update method to override the update pattern used.
--------------------------------------------------------
1 line of code equals many bugs. So don't write any!!
My mad coder blog
|
|
|
|
|