How can the following be achieved in a strongly typed dataset ? int n = (int)Tables[0].Rows[0]["Field1", DataRowVersion.Original]; Thx
paper67
Posts
-
Original datarow value. -
Point conversion.Hi, What is the best way to convert a point string to a point object ? Point Pt1 = new Point(10, 20); string strPt = Pt1.ToString(); Point Pt2 = ? (use strPt to convert back to Point object) Thx.
-
Xml validation. Please help.I want to validate an XML file through a schema.
<?xml version="1.0" encoding="utf-8" ?>
<Units>
<Unt Text="stuks" Service="False" Value="0" />
<Unit Text="km" Service="True" Value="1" />
</Units><?xml version="1.0" encoding="utf-8"?>
<xs:schema id="Unit" targetNamespace="http://tempuri.org/Unit.xsd" elementFormDefault="qualified" xmlns="http://tempuri.org/Unit.xsd"
xmlns:mstns="http://tempuri.org/Unit.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema"><xs:complexType name="UnitType">
<xs:attribute name="Text" type="xs:string" use="required" />
<xs:attribute name="Service" type="xs:boolean" use="required" />
<xs:attribute name="Value" type="xs:byte" use="required" />
</xs:complexType><xs:element name="Units">
xs:complexType
<xs:sequence minOccurs="0" maxOccurs="unbounded">
<xs:element name="Unit" type="UnitType" />
</xs:sequence>
</xs:complexType>
</xs:element></xs:schema>
I use the following code :
Settings = new XmlReaderSettings();
Settings.ValidationType = ValidationType.Schema;
Settings.Schemas.Add("http://tempuri.org/Unit.xsd", Directory.GetCurrentDirectory() + strXmlSchema);
Settings.ValidationEventHandler += new ValidationEventHandler(OnSchemaValidationError);using (XmlReader Reader = XmlReader.Create(Directory.GetCurrentDirectory() + strXmlFile, Settings))
{
if (Reader != null)
{
XmlDocument Doc = new XmlDocument();
Doc.Load(Reader);
Reader.Close();
:
}
}My handler OnSchemaValidationError never gets called, even when there is clearly a mistake in my XML. Why ??
-
Accessing dataset throughout application.I am writing a C# windows forms application. It is a MDI application with lots of seperate forms. They all need to get to tables within a DataSet. What is the best way to make this DataSet "Global" for all forms within the application ? My main thought is to create a static class. Create a static method that returns the dataset. Is this good programming practise ???
-
UI, BLL and DALSo when I intend to keep the wizards autogenerated code, referencing the DAL in the UI layer to access the typed dataset, datatable and datarow types returned from the BLL is not so bad ??
-
UI, BLL and DALHi, I'm trying to come up with the architecture for my new project. It's a window form based application with a SQL Server backend. I would like to use a multi-tiered approach with the database, a data access layer, a business logic layer and a user interface layer. The structure of the solution is as follows - DAL (Class Library) - BLL (Class Library) - UI (Window form application) From what I understand, the UI should not have access to the DAL (except via the BLL), so there should be no reference to the DAL in the UI. Wright ? I use the "TableAdapter Configuration Wizard" to generate my DAL code, which sometimes returns typed datatables. The businesslogic layer returns those same typed datatables that were defined in the DAL. I'm setting the data source of a gridview to that typed datatable. This requires that the UI know something about the datatable defined in the DAL, so to make this work I have to place a reference to the DAL in my UI layer, which I supose is not good programming practise. How should this be done ??
-
DataBindings, BindingContext's, CurrencyManagers etc...Just curious. I have a master form with a DataGridView on it showing me the records of a DataTable. The same form also holds 3 buttons. (An "Insert", "Update" and "Delete" button). Clicking "Insert" I do : CustomerForm Form = new CustomerForm(m_CustomerDT.NewCustomerRow()); : if (Form.ShowDialog() == DialogResult.OK) m_CustomerDT.AddCustomerRow(Form.CustomerRow); Clicking "Update" I do : CustomerForm Form = new CustomerForm(m_CustomerDT[DataGrdVw.SelectedRows[0].Index]); : Form.ShowDialog(); In the CustomerForm_Load handler I initialize my CustomerForm controls like : if (!m_CustomerRow.IsNull("LastName")) { LastNameTxtBx.Text = m_CustomerRow.LastName; : } In the OKButton_Click handler I do the opposite, saving the values back in the DataRow. Everything works fine that way, but is it the correct way to go ?? Shouldn't I use DataBindings, BindingContext's, CurrencyManagers etc ... If so, why and how should that translate for my context ?
-
Custom sorting a column in a databound DataGridView control.I am trying to implement a simply task that appears to be amazingly hard to accomplish in .Net: Sorting a column in a datasource bound control (e.g. DataGridView), not based on the underlying values (i.e. simple string comparison on the values) but on some custom rule that I want to define. I have a DataGridView that is bound to a Bindingsource which in turn is (via Dataview, .Net internal stuff...) bound to a Datatable. This is plain vanilla stuff, out of the box. If I was happy with the default sort behavior, i.e. sorting columns by the values in DataTable, everything would be easy, even automatic. However, some of the contents in the Datatable is not in a user-friendly format, so it must be formatted for display in the datagridview (e.g. by overriding the CellFormatting event). If I now sort the control by that column, the rows will be sorted by the underlying values, and not by the displayed text, which is bad. I cannot use the Sort() function nor the IComparer overwrite of the DataGridView since I am working in databound mode. How in the world then can I intercept the sorting mechanism and tell the DataGridView how to sort this column properly? It strikes me as odd that the standard data source - binding source - control model in .Net appears to have no provision at all for custom sorting! What is even odder is that a primary reason for the whole concept of a BindingSource is just sorting and filtering! There must be an easier way than writing 1000s of lines of code to create my own DataView or IBindingList derived class that will allow this kind of customization, as recommended in various articles. This seems such a common scenario that I can't believe there is a more elegant way...
-
Dataset folderHi, To get some more structure in my window form application, I want to move a DataSet in a custom "DAL" folder. For some reason I cannot reopen the Dataset in the designer. Get following error : "Value does not fall within the expected range". When I place it in the root folder everything works fine. Why ? TIA
-
Forcing full postback in UpdatePanelThx for the reply. I appreciate your effort. I tested your code, and yes it works, but in my case I use form views which creates their embedded controls dynamically. I found numerous examples on the net, demonstrating how it has to be done, but I found none which resembles my senario. For one reason or another my code does not function, and I would like to know why.
-
Forcing full postback in UpdatePanelHi, I have basically the following structure set up :
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:GridView ID="GridView1" runat="server" DataSourceID="ObjectDataSource1" ... >
:
</asp:GridView>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" ... >
</asp:ObjectDataSource>
<asp:ImageButton ID="NewInsertButton" runat="server" OnClick="NewInsertButton_Click" />
<asp:FormView ID="FormView1" runat="server" DataSourceID="ObjectDataSource2" ... >
<InsertItemTemplate>
:
<asp:FileUpload ID="FileUpload1" runat="server" />
:
<asp:ImageButton ID="ImageButton1" runat="server" CommandName="Insert" />
</InsertItemTemplate>
:
</asp:FormView>
<asp:ObjectDataSource ID="ObjectDataSource2" runat="server" ... >
</asp:ObjectDataSource>
</ContentTemplate>
</asp:UpdatePanel>I am aware that a FileUpload requires a full page postback. I read the article http://www.4guysfromrolla.com/articles/090209-1.aspx[^] I tried to install a PostBackTrigger programmatically to get a full postback only on the ImageButton1 control. All other postbacks must be partial. (GridView sorting, paging, ...) In code behind I do :
protected void NewInsertButton_Click(object sender, ImageClickEventArgs e)
{
FormView1.ChangeMode(FormViewMode.Insert);
FormView1.DataBind();
ImageButton InsertButton = FormView1.FindControl("ImageButton1") as ImageButton;
if (InsertButton == null)
throw new NullReferenceException("ImageButton1");
ScriptManager Manager = ScriptManager.GetCurrent(Page);
if (Manager == null)
throw new NullReferenceException("ScriptManager");
Manager.RegisterPostBackControl(InsertButton);
:
}The above code does not seem to install a full postback only for the ImageButton1, so the file upload fails. How can I make this work ?
-
Current themeFound it. In my JavaScript method I got the path as follows :
string strImageThemePath = string.Format("{0}/App_Themes/{1}/{2}", Page.Request.ApplicationPath, Page.StyleSheetTheme, m_strDeleteImageUrl);
Thanks Michael for your help.
-
Current themeI already tried that. Even in the JavaScript method Page.Theme is null. Could it have to do the way I set my theme. In web.config I do :
<pages styleSheetTheme="Sunset">
<controls>
:
</controls>
</pages>tia
-
Current themeCorrect. I followed your link, but I cann't see any answers. Basically what I do is the following: On the Page_Load event of the user control I inject javascript.
ScriptManager.RegisterStartupScript(this, typeof(Page), "MultiFileUploadScript", GetJavaScript(), false);
private string GetJavaScript()
{
StringBuilder JavaScript = new StringBuilder();
:
JavaScript.Append("var deleteImage = null;\n");
if (m_strDeleteImageUrl != string.Empty)
{
JavaScript.Append("deleteImage = new Image();\n");
JavaScript.AppendFormat("deleteImage.src = '{0}';\n", m_strDeleteImageUrl);
JavaScript.AppendFormat("deleteImage.setAttribute('alt','{0}');\n", m_strDeleteText);
}
:
return JavaScript.ToString();
}How can I make m_strDeleteImageUrl point to the correct theme image ? tia
-
Current themeI placed the following line in a .skin file.
<UC:MultiFileUpload runat="server" UpperLimit="10" Rows="5" ListItemHoverColor="#F2D76A" DeleteImageUrl="Img/Delete.png" />
-
Current themeHi, DeleteImageUrl is an exposed property of the user control.
public string DeleteImageUrl
{
get { return m_strDeleteImageUrl; }
set { m_strDeleteImageUrl = string.Format("~/App_Themes/{0}/{1}", this.Page.Theme, value); }
}this.Page is null here. Why ?
-
Current themeHow to get the current theme from within a UserControl ?
-
Applying theme to User Control.I have a User Control that has a custom property, which I want to set by a theme. The custom property is used in javascript that is injected into the page by a Page.ClientScript.RegisterStartupScript method in Page_Load. Basically I do the following : - Placed a [Themeable(true)] attribute above my user control class. - I register my user control in web.config.
<pages styleSheetTheme="Sunset">
<controls>
<add tagPrefix="UC" src="~/UserControls/MyUserControl.ascx" tagName="MyUserControl"/>
</controls>
</pages>- Placed a skin file under Sunset directory in App_Themes with content :
<UC:MyUserControl runat="server" CustomColor="#FF0000" />
At runtime everything works fine, but in the designer I keep getting the error : Error Rendering Control An unhandled exception has occured. There was an error parsing the theme: The control type "System.Web.UI.UserControl" cannot be themed. What am I missing here ? tia
-
Multiple file uploadEmail: paperke67@hotmail.com tia
-
Multiple file uploadHi, I want to upload multiple image files from within an InsertItemTemplate within a FormView. That Formview is placed in an UpdatePanel. I searched the net for 2 days to find answers to my problem. I am aware that a full postback is required to make the asp.net FileUpload control work and that a PostBackTrigger has to be set inside the UpdatePanel. My problem is that the PostBackTrigger button that I place in the Triggers section of the UpdatePanel can not be found since it is declared in the InsertItemTemplate. Can this be solved some way. I have read that in this case it is better to use an AJAX AsyncFileUpload control, but I can not find any examples where multiple files can be uploaded. I doubt that this is the best way to solve my problem since the upload starts immediately after a file on the local file system is selected. I want to start the upload only when the Insert Button inside the InsertItemTemplate is clicked and therefore do the handling in the ItemInserting event of the FormView. Can anyone please point me to an example where this is done. I can not imagine I am the only one having this problem. tia