Posts

Showing posts with the label GridView

Donate

Set GridView Lines And Pager Background Color In ASP.NET Web Forms

Usually, in ASP.NET 2.0, setting the GridView lines through property should work. However in 4.5, it doesn't seem to render correctly. One blog pointed out to set the gridlines through it's row data bound property as demonstrated on the code below: Aspx Markup <asp:GridView ID= "GridView1" runat= "server" DataSourceID= "SqlDataSource1" BorderColor= "Black" BorderStyle= "Solid" PageSize= "2" AllowPaging= "True" OnRowDataBound= "GridView1_RowDataBound" BackColor= "White" CellPadding= "3" > <FooterStyle BackColor= "White" ForeColor= "#000066" /> <HeaderStyle BackColor= "#006699" Font-Bold= "True" ForeColor= "White" /> <PagerStyle BackColor= "White" ForeColor= "#000066" HorizontalAlign= "Justify" Wrap= "True"

ASP.NET Gridview Not Getting New Values In RowUpdating() Event

Assuming in your row updating event, you do some editing in your textbox and then click update button. The event in turn saves your modified records to the database. However, when you tried rebinding the datasource of Gridview it seems that you didn't get the newly updated values. The simple trick would be to set the Gridview property EnableViewState to false .

A field or property with the name 'ClassName.Property' was not found on the selected data source In ASP.NET Gridview

As i was running an asp.net application in my local machine, I encountered an exception which is the title of this post. This asp.net app runs perfectly from the other workstation. I tried searching solutions in google but found out that most of the recommendations were to redo the model or the business tier. One option I tried was to replace the BoundField of the gridview with TemplateField with label as the bound control using Eval("expression"). Glad that worked. It could be an IIS issue as stated in other forums. Here's the gridview markup changes: (Windows 7 64 Bit using BoundField) <asp:BoundField DataField= "Product.Name" HeaderText= "Name" > <ItemStyle Width= "350px" /> </asp:BoundField> (Windows 7 32 Bit using TemplateField) <asp:TemplateField HeaderText= "Product Name" > <ItemStyle Width= "350px" /> <ItemTemplate> <asp:Label ID= &quo

How To Highlight GridView Row On Click In ASP.NET Web Forms

This is based from the article of Vincent Maverick Durano's blog on HIGHLIGHT GRIDVIEW ROW ON CLICK AND RETAIN SELECTED ROW ON POST BACK. I just added some statements on javascript to check if the selected row is less than total gridview row count and server side code for paging. JAVASCRIPT CODE: <script type= "text/javascript" > var prevRowIndex; function ChangeRowColor(row, rowIndex) { var parent = document.getElementById(row); var currentRowIndex = parseInt(rowIndex) + 1; //count number of gridview rows var rowscount = $( "#<%=grdCustomer.ClientID %> tr" ).length; if (prevRowIndex == currentRowIndex) { return ; } else if (prevRowIndex != null ) { parent.rows[prevRowIndex].style.backgroundColor = "#FFFFFF" ; } //check if current index is a number... if (IsNumeric(currentRowIndex)) { //check if row index

Simple Pager Template in ASP.NET Web Forms

Here's a simple pager template in ASP.NET Web Forms. < PagerTemplate > Page: <%= gvPRocess.PageIndex + 1%> of <%= gvPRocess.PageCount %> < asp:button ID = "btnFirst" runat = "server" CommandName = "Page" CommandArgument = "First" Text = "<<" /> < asp:button ID = "btnPrev" runat = "server" CommandName = "Page" CommandArgument = "Prev" Text = "<" /> < asp:button ID = "btnNext" runat = "server" CommandName = "Page" CommandArgument = "Next" Text = ">" /> < asp:button ID = "btnLast" runat = "server" CommandName = "Page" CommandArgument = "Last" Text = ">>" /> </ PagerTemplate >

Show Processes From Your Computer Using ASP.NET Web Forms

Here's a sample code on how to display processes using Process.GetProcesses() method from Process class and bind it to the GridView Control. Code behind: protected void ShowProcessToGrid() { Dictionary< string , string > process = new Dictionary< string , string >(); foreach (Process p in Process.GetProcesses()) { process.Add(p.Id.ToString(),p.ProcessName); } this .gvPRocess.DataSource = process; this .gvPRocess.DataBind(); } protected void gvPRocess_PageIndexChanging( object sender, GridViewPageEventArgs e) { gvPRocess.PageIndex = e.NewPageIndex; ShowProcessToGrid(); } Here is the aspx markup: <asp:GridView ID= "gvPRocess" runat= "server" AllowPaging= "True" BackColor= "White" BorderColor= "Black" BorderStyle= "Solid" BorderWidth= "1px" CellPadding= "4" style= "margin:auto"

How To Get ASP.NET Web Forms GridviewRow Selected Index In Row Command Event

In your row command event, add a code like this: int selected_index = Convert.ToInt32(e.CommandArgument);

ASP.NET Web Forms GridView RowUpdating Event Not Getting New Values From Controls

I have a code in rowupdating event which get's values from textbox controls during edit mode. However, when update command button is clicked, the values from the controls were cleared or null. So, I checked the page load event, and found out that I have a code which rebinds the grid when it is not post back since the update link button will trigger postback. Here is the page load code: if (! string .IsNullOrEmpty(Request.QueryString[ "LoanNum" ])) { ShowToControls(Convert.ToInt32(Request.QueryString[ "LoanNum" ])); BindGridDetails(Convert.ToInt32(Request.QueryString[ "LoanNum" ])); } So, the modified pageload code should add a IsPostback condition so that the binding of gridview will not be executed. Here's the modified script: if (! string .IsNullOrEmpty(Request.QueryString[ "LoanNum" ]) && !Page.IsPostBack) { ShowToControls(Convert.ToInt32(Request.QueryString[ "LoanNum" ])); BindGridDe

Highlight ASP.NET Web Forms GridView Row Using JavaScript

Here's the code on how to highlight an ASP.NET Web Forms GridView row using JavaScript. if (e.row.rowtype == DataControlRowType.DataRow) { e.Row.Attributes.Add( "onclick" , "document.getElementById('" + e.Row.ClientID + "') .style.backgroundColor = 'green';" ); }

Code In Gridview RowDatabound Not Working If Rowstate Is Alternate|Edit In ASP.NET Web Forms

In a gridview rowdatabound event I have this condition to check if rowstate is in edit mode: if (e.Row.RowState == DataControlRowState.Edit) //row is in edit mode { TextBox actdaterec = (TextBox)e.Row.Cells[1].FindControl( "txtDateRec" ); actdaterec.Text = string .Empty; TextBox cashRec = (TextBox)e.Row.Cells[2].FindControl( "txtCashReceived" ); cashRec.Text = string .Empty; } The code above usually works if the rowstate is in edit mode, however on the succeeding rows the rowstate becomes Alternate|Edit . The code above does not work. So the solution would involve C# bitwise operator (&) . See the revised code below: if ((e.Row.RowState & DataControlRowState.Edit) > 0) //row is in edit mode { TextBox actdaterec = (TextBox)e.Row.Cells[1].FindControl( "txtDateRec" ); actdaterec.Text = string .Empty; TextBox cashRec = (TextBox)e.Row.Cells[2].FindControl( "txtCashReceived"

Format Date Values Shown In Label Control Inside An ASP.NET Web Forms Gridview

Reference: Set Date Format in Gridview To format date as short date format of a label control inside a template field use Bind() as shown below: 1: <ItemTemplate> 2: <asp:Label id= "lblDateRec" runat= "server" Text= '<%# 3: Bind("GeneratedDateRec", "{0:MM/dd/yyyy}") %>' ></asp:Label> 4: </ItemTemplate>

Gridview Samples From MSDN

Here's a link of samples from MSDN. I have'nt tested all of them, but this might help to other developers out there. GridView Examples for ASP.NET 2.0

Donate