Pretty cool, can be used for many purposes, like generating the decryption and validation machine keys, etc…
Pretty cool, can be used for many purposes, like generating the decryption and validation machine keys, etc…
There are many ways to select a row and perform whatever actions you desire in GridView. The easiest is to let its CommandField generate the select button and use the SelectedIndexChanging and SelectedIndexChanged events for the actions desired.
<asp:CommandField ShowSelectButton="true" />
However, it would be more elegant if you can just select the row. 3 steps needed in order to achieve that:
Step 1: Add the SELECT command in RowDataBound event to each row (Assuming the ID of your GridView is “myGridView“)
protected void PeopleGridView_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { // Just adding styles and effects e.Row.Attributes["onmouseover"] = "this.style.cursor='hand';this.style.textDecoration='underline';"; e.Row.Attributes["onmouseout"] = "this.style.textDecoration='none';"; e.Row.Attributes["onclick"] = ClientScript.GetPostBackClientHyperlink(this.myGridView, "Select$" + e.Row.RowIndex); } }
Step 2: Register these SELECT commands in Render to avoid the Event Validation errors
protected override void Render(HtmlTextWriter writer) { for (int i = 0; i < this.myGridView.Rows.Count; i++) { Page.ClientScript.RegisterForEventValidation(this.myGridView.UniqueID, "Select$" + i); } base.Render(writer); }
Step 3: Use the SelectedIndexChanging and SelectedIndexChanged events for the actions desired
Just use HttpUtility.Encode because Server.HttpEncode simply calls HttpUtility.Encode. Basically if you are trying to display text back to the user and these text are either straight from database, or from databound objects, or from current page textbox entered by user, etc, use HttpUtility.Encode, mainly to prevent script-injection and handle specials characters such as blanks and punctuations, and <, >, etc…
Example:
TextBox TextBoxRoleName = (TextBox)RolesGridView.FooterRow.FindControl(“TextBoxRoleName”);
string newRoleName = TextBoxRoleName.Text.Trim();
LabelMessage.Text = “Role ‘” + Server.HtmlEncode(newRoleName) + “‘ already exists.”;
Of course, this leads to some quite important MSDN articles:
The last two articles of the above are under the following bigger, boarder title:
ASP.NET AJAX username availability check with UpdatePanel
ASP.NET AJAX username availability check without UpdatePanel
I used UpdatePanel in our project and it works alright. I didn’t read either of these posts when I did it. It was not too hard to figure out even though I did remember myself having some issues. However, the web service method is much much better and well worth the time to learn and implement.
Great great posts from both sites!
If you set the TargetControlID of both ModalExtender and RoundedCornerExtender to one panel, ASP.NET will not like it, probably because of some JavaScript clashes.
One simply trick is to have an inner panel, surrounded by an outer panel. Set the outer panel’s background color to transparent and let the inner panel have the rounded corner extender.
Like so: (key is the transparent)
.modalPopupOuter {
background-color:Transparent;
padding:10px 10px;
width:700px;
height:520px;
}
.modalPopupInner {
background-color:#ffffff;
padding: 10px;
width:700px;
height:500px;
}
The screen shot below doesn’t have rounded corners, but it has a stand-out “X” on the top-right corner, that’s achieved by having the transparent outer panel, obviously.

Apparently scroll bar styles are only supported by IE. Diddn’t realize this until today.
Regardless, I think it’s a pretty cool thing to have and Firefox and Safari will eventually adopt it. Here’s a site to generate the CSS codes. It’s pretty darn good…
http://www.spectrum-research.com/V2/projects_scrollbar_generator.asp
http://www.spectrum-research.com/V2/generators/scrollbar.asp