use OnClientClick of LinkButton with bound data
June 6, 2009
I have some linkButtons in GridView, and I want to call a client-side javascript method with bound data when user click on it.
<asp:LinkButton OnClientClick=’<%# “alert(‘” + Eval(“something”) + “‘)” %>’ ……>
unfortunately, it doesn’t work.
<asp:LinkButton OnClientClick=’<%# Eval(“something”, “alert(‘{0}’)” %>’ ……>
it doesn’t work too.
Only works for me when use codebehind:
protected void GridView1_OnRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
LinkButton lnkbtn = (LinkButton)e.Row.FindControl("lnkbtn");
string st= DataBinder.Eval(e.Row.DataItem, "something").ToString();
lnkbtn.Attributes.Add("onclick", string.Format("alert('{0}')", st));
}
}
Data-Bound controls
March 5, 2009
Data-bound controls are used to bind/connect to data. Their common root is BaseDataBoundControl which is abstract with property “DataSource” and “DataSourceID” and “DataBind()” method, so that all the data-bind control can retrive data items from DataSource objects. They can be separated by their direct base classes into 3 types:
- simple (BulletedList/DropDownList/RadioButtonList/CheckBoxList/ListBox)
- composite (GridView/DetailsView/FormView/DataList/DataGrid/Repeater)
- hierarchical (Menu/TreeView)

The usage of a simple data-bound control is simple. The common things to do are:
- create and initialize an object of the control(either by drup&drop or programmingly)
- set the DataSource property
- Set the DataTextField & DataValueField
- call the DataBind() of the control
The GridView control displayed data with each cell holding one field of information of one record; DataList/Repeater render one record per cell.
DetailsView and FormView can do insert new records. FormView/DetailsView has a property “DefaultMode” that can be set as insert/edit/readOnly. GridView, DataList, and Repeater can not create new records. A common solution is to display existing records in the GridView and create a button on the GridView that goes to a DetailsView (which can be on the same page or a second page) for inserting a new record. The DetailsView can open in INSERT DefaultMode, ready to accept the values for the new record.
The only difference between DetailsView and FormView is DetailsView has a set of templates, whereas FormView is a blank slate upon which users build templates as desired. DataList has a default formatting and templates whereas the Repeater requires more setup by the designer.
Style, CSS and Theme in ASP.NET
March 4, 2009
Themes are used to define the look and feel of a web site, similarly to how pages are styled using CSS. However, unlike CSS, themes can specify how server-side elements, like a TreeView control. A theme can be used in one of two ways.
- A theme can be used as a Stylesheet theme, which acts in a similar way to a regular CSS style sheet.
- The alternative is to use your theme as a Customization theme, which changes the order of preference for style rules that you may be used to, so that the Customization theme will specify the style to use for each element, overriding any style preferences specified in a separate style sheet, or even in the style attributes of an element.
Rules:
- HTML elements with class attributes specified can also have additional style information specified in the Style attribute.
- Any styles defined in the Style attribute will override those specified in the CSS file.
- In asp.net, the CssClass of a server control will be converted to the HTML element’s “class”, and the custom style attributes (control properties) will be converted into “style”.
- In asp.net, the attributes and elements take the order precedence ( from high to low) as:
- Theme in @page directive (customization theme) _ A Customization theme has total control over the styling of elements on the page.
- <pages Theme=”theThemeName”> in web.config file _ customization theme on the site.
- local control attributes
- CSS styles
- StyleSheetTheme in @page directive (stylesheet theme) _ stylesheet theme on the page.
- <pages StyleSheetTheme=”theThemeName”> in web.config _ stylesheet theme on the site.
For example, the settings in the directive applying a theme would override the control propertities. If want to completely control the appearance of an entire site, use a
Customization theme in the Web.config file.
