@bobnoordam

Category: ASP.NET Webforms

Hiding a control’s commandfield button at runtime

Hiding a command button at runtime can be archieved by casting the commandfield in the DataBound event, and accessing the buttons from there. The sample below shows the hiding of a button based on a security role. protected void DetailsViewDocuments_DataBound(object sender, EventArgs e) { // Check role string currentuser = Common.GetRequestUser(); // some user retrieval […]

Custom DataContext and Query with a Gridview bound to a LinqDataSource

Using an editable grid with a LinqDatasource with a custom connection string and query Binding to a custom datasource Create a custom datacontext object connected to the database to be used; private string _database; private SomeDataContext _dc; protected void Page_Load(object sender, EventArgs e) { _database = Common.GetRequestConnectionString(); _dc = new SomeDataContext(_database); } Catch the contextcreating […]

Setting the column width on a gridview column from code

To set the widht of a column on a GridView in ASP.NET you can hook into the RowDataBound event. This code detects the header line (datacontrolrowtype.header) and then hooks in to set the width of the columns. Instead of percentages you can use any Unit.* measure you like (pixels, mm) VB.NET Example Private Sub GridView1_RowDataBound(ByVal […]

Validation of a detailsview field against a numeric value

Validation of a field inside a detailsview does not need to be done with the Updating or Editing events, but can be accomplished by a simple validation control in the markup language. Convert the field in the detailsview to a template field, and use a standard validation control. <asp:CompareValidator ID=”CompareValidator2″ runat=”server” ErrorMessage=”Numeric input required” Operator=”DataTypeCheck” […]

Changing a field into a date editor

The following example shows the markup for a DATETIME field from a database bound to a ASP.NET DetailsView before and after converting it into a templatefield and binding it to the ASPxDateEdit control. Default markup after converting to a template field: <asp:TemplateField HeaderText=”GebDat” SortExpression=”hrGebDat”> <EditItemTemplate> <asp:TextBox ID=”TextBox2″ runat=”server” Text='<%# Bind(“hrGebDat”) %>’></asp:TextBox> </EditItemTemplate> <InsertItemTemplate> <asp:TextBox ID=”TextBox2″ […]

Next Page »