Archive / C#

RSS feed for this section

GridView.RowDataBound Event No Data

I was trying to use the GridView.RowDataBound event to change the background color of the row in a GridView. But the data was missing. Here is what I trying: void gvReport_RowDataBound(Object sender, GridViewRowEventArgs e){   if (e.Row.RowType == DataControlRowType.DataRow)   {      if (e.Row.Cells[1].Text.IndexOf(“Total:”) > 0)         e.Row.BackColor = System.Drawing.Color.FromArgb(247, 249, 223);   }} But my e.Row.Cells[1].Text had no data in it. I am binding […]

Code to create a DataSet

Use this code to create a table and place it in a DataSet. // Create a new DataTable.System.Data.DataTable table = new DataTable(“Details”);// Declare variables for DataColumn and DataRow objects.DataColumn column;DataRow row;// Create new DataColumn, set DataType, // ColumnName and add to DataTable. column = new DataColumn();column.DataType = System.Type.GetType(“System.Int32”);column.ColumnName = “fk_agent_id”;column.ReadOnly = false;column.Unique = true;// Add the Column to […]

Code to create a DataRow and add it to a DataSet

Use this code to create a DataRow from a table in a DataSet and place it in the table in a DataSet. // Call a method to create the DataSet with a table in it.DataSet resultData = MakeDetailTable();DataRow row = resultData.Tables[“Details”].NewRow();row[“fk_agent_id”] = userInfo.account_id;row[“agent_name”] = userInfo.lname + “, “ + userInfo.fname;resultData.Tables[“Details”].Rows.Add(row);// Use the data in the GridView.gvReport.DataSource = […]

C# Fill a Dropdown List and For Loop

Here is a quick syntax for a For loop and filling a dropdown list with an incrementing number using C#. for (Int16 i = 1; i <= iMax; i++) {    ListItem item = new ListItem(i.ToString()); ;    ddlNumber.Items.Add(item); }