Mohammed Atef’s Technical blog

Link Asp.net Dynamic Data Entity item to customized web pages

Introduction

When we build ASP.NET applications that sit on top of a data store of some kind, there are always a set of common tasks that we need to provide a UI for. Just a few of these patterns are listed here:
Entity Lists — Display a list of rows in a table.
Detail Form — Displays the details of a single entity.
Edit Form — Enables the user to edit the details of a single entity.
Create — Adds a new entity to a list.
Delete — Deletes an entity from a list.
Navigation — Provides Search, Filter, Sort, and Paginate lists of entities.

Problem definition

sometimes we need to link one of entity list to another customized screens we have implemented before, so how we can do this task?

Solution

Here we are going to link one of listed entities in web application entities list to another existing or customized page throw the binding event of Grid View of listed entities.

so if we have assumed that the entity name called Site and the customized page called siteslist.aspx, we can write the following lines of codes to redirect to this customized page when user select Site entity from entities list

 1: protected void Menu1_RowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
 2:         {
 3:             if(e.Row.RowIndex!=-1)
 4:             {
 5:                if (((System.Web.DynamicData.DynamicHyperLink)e.Row.Cells[0].Controls[1]).Text == "Site")
 6:                 {
 7:                     ((System.Web.DynamicData.DynamicHyperLink)e.Row.Cells[0].Controls[1]).NavigateUrl = Request.Url.ToString().Trim().ToLower().Replace("default.aspx","SitesList.aspx");
 8:                 }
 9:              }
 10:         }

I think these few lines of code is very clear as shown above i have get the grid view row that has Site entity and replaced it’s NavigateUrl with the new siteslist.aspx page.

Note, there is very important note that you should use customized screen like siteslist.aspx which note linked to master page if this page in the same web application else you can use any kind of web pages.

I Hope that helped

Advertisements

May 10, 2011 Posted by | .Net 2010 | , , , | 1 Comment

How to work around the access denied cross-domain frame issue in ASP.NET Ajax 1.0 AutoComplete Extender

Introduction
It is common issue for using Asp.net Ajax 1.0 autocompelete in Iframe throw Cross domain. I am not going to explain solution as you can find it here.

Download

But to help you i have uploaded MicrosoftAjax.js,MicrosoftAjax.debug.js and AjaxControlToolkit.dll after applying updates required as mentioned at link above.

So have fun and download these files from here.

March 22, 2010 Posted by | Asp.net | , , , | Leave a comment

Master Details GridView with Details inside same GridView

Introduction

I have been worked for implementing Gridview which contain linkbutton in each row that link must be show user details in same row using Detail View Control.

Solution

I have developer normal Gridview and did the following steps

1-drag GridView and Detail view control into my page

2- bind Gridview in page load event

3- add 3 template fields and one command select field

4-add labels with unique names in each template field

5-add the following code in GridView RowCommand Event
 

   1: If e.CommandName = "Select" Then
   2:             Dim userid As String = CType(GridView1.Rows(Integer.Parse(e.CommandArgument)).Cells(0).FindControl("lbluserid"), Label).Text
   3:             DetailsView1.DataSource = GenerateUserDetTable(GenerateUserDetTable(Nothing).Select("userID=" + userid)(0))
   4:             DetailsView1.DataBind()
   5:             GridView1.Rows(Integer.Parse(e.CommandArgument)).Cells.RemoveAt(0)
   6:             GridView1.Rows(Integer.Parse(e.CommandArgument)).Cells.RemoveAt(1)
   7:             GridView1.Rows(Integer.Parse(e.CommandArgument)).Cells(0).Text = ""
   8:             GridView1.Rows(Integer.Parse(e.CommandArgument)).Cells(0).ColumnSpan = 2
   9:             GridView1.Rows(Integer.Parse(e.CommandArgument)).Cells(0).HorizontalAlign = HorizontalAlign.Center
  10:             GridView1.Rows(Integer.Parse(e.CommandArgument)).Cells(0).Controls.Add(DetailsView1)
  11:             Dim lnk As LinkButton
  12:             lnk = New LinkButton
  13:             lnk.CommandName = "Hide"
  14:             lnk.Text = "Hide"
  15:             GridView1.Rows(Integer.Parse(e.CommandArgument)).Cells(1).Text = ""
  16:             GridView1.Rows(Integer.Parse(e.CommandArgument)).Cells(1).Controls.Add(lnk)
  17:         End If

Understanding Code

the whole idea is to remove not needed cells and reset the Column span for the remaining cell and adding detailView into this cell lets see how you can do this

at line 1 i get user is from row that user click show linkbutton there

at lines 5,6 i have removed not needed cells

at lines 8,9,10 i have update remaining cell properties and add Detailview to it

at lines 11 to 16 i have create new linkbutton and replace it with the Show link button

note that GenerateUserDetTable is a method that generating UserDetails Table

you can download the whole project from here


Hope that helped.

September 30, 2009 Posted by | .Net 2010, C#,VB.Net | , , , , , | Leave a comment

AutoComplete DropDownList using JavaScript

Introduction

Today I am going to present VB.net method that create AutoComplete DropDownlist dynamically .I have used JavaScript code for generating AutoComplete DropDownlist from this site

I have created two methods one for creating dropdown list and another to create Div control dynamically. second method use RegisterStartupScript method for registering some java script code used in my sample.

First method code like following

Public Function CreateDDL() As DropDownList
Dim ddl As DropDownList
ddl = New DropDownList
ddl.Attributes.Add(“name”, “alfa1”)
ddl.ID = “combo_zone1”
ddl.Items.Add(“aaaa”)
ddl.Items.Add(“aa1”)
ddl.Items.Add(“aas”)
ddl.Items.Add(“asdf”)
ddl.Items.Add(“bbb”)
ddl.Items.Add(“b111”)
ddl.Items.Add(“bbb43”)
ddl.Items.Add(“ddd”)
ddl.Items.Add(“dbbd”)
ddl.Items.Add(“eee”)
ddl.Items.Add(“eeea”)
ddl.Items.Add(“aase”)
ddl.Items.Add(“nnnmmm”)
ddl.Visible = True
Return ddl
End Function

I think it is clear method I have just create DropDownlist and assign name attribute and id for it and finally added some items

Second method fond below

Public Sub CreateDiv()
Dim dv As New HtmlControls.HtmlGenericControl(“DIV”)
dv.ID = “newdv”
dv.Attributes.Add(“class”, “content”)
dv.Controls.Add(CreateDDL())
Dim scriptstr As String = “”
scriptstr = “<script type=’text/javascript’>”
scriptstr = scriptstr + ” ” + “var z=dhtmlXComboFromSelect(‘combo_zone1’);”
scriptstr = scriptstr + ” ” + “z.enableFilteringMode(true);”
scriptstr = scriptstr + ” ” + “</script>”
dv.Visible = True
form1.Controls.Add(dv)
Page.ClientScript.RegisterStartupScript(Me.GetType(), “startup”, scriptstr)
End Sub

At this method I have created div control dynamically

And I have added the DropDownlist control from by calling the first method and finally I have register the JavaScript code into this div.

You can donload full sample from here

I hope that helped.

September 13, 2009 Posted by | Asp.net | , , , , | Leave a comment