Hi all...
I have a gridview in all the web pages in my portal.
I have to do the following things in it on RowDataBound -
1. Column Headings and Cell Values - Maximum 20 characters; rest in tooltip.
2. Column-19 is boolean value. If it is true - Row enabled = true; if false, row enabled = false;
3. All values to be aligned to left side.
I have written the folllowing code -
protected void grid_Emp_RowDataBound(object sender, GridViewRowEventArgs e)
{
try
{
int i = 0;
DataRowView drview = e.Row.DataItem as DataRowView;
if (e.Row.RowType == DataControlRowType.DataRow || e.Row.RowType == DataControlRowType.Header)
{
#region EditableAndUnEditableRows
Boolean b1 = Convert.ToBoolean((drview[19])); // if (drview[5].ToString() == "True")
if (b1 == true)
{
e.Row.Enabled = false;
// e.Row.BackColor = System.Drawing.Color.LightSlateGray;
}
else if (b1 == false)
{
e.Row.Enabled = true;
}
#endregion
#region HorizontalAlignLeft
if (e.Row.RowType == DataControlRowType.DataRow || e.Row.RowType == DataControlRowType.Header)
{
foreach (TableCell cel in e.Row.Cells)
{
i++;
string s = cel.Text;
if ((cel.Text.Length > 20 && i == 1) || (cel.Text.Length > 20 && i == 2) || (cel.Text.Length > 20 && i == 3) ||
(cel.Text.Length > 20 && i == 4) || (cel.Text.Length > 20 && i == 5) || (cel.Text.Length > 20 && i == 6) || (cel.Text.Length > 20 && i == 7) || (cel.Text.Length > 20 && i == 8) ||
(cel.Text.Length > 20 && i == 9) || (cel.Text.Length > 20 && i == 10) || (cel.Text.Length > 20 && i == 11) || (cel.Text.Length > 20 && i == 12) ||
(cel.Text.Length > 20 && i == 13) || (cel.Text.Length > 20 && i == 14) || (cel.Text.Length > 20 && i == 15) || (cel.Text.Length > 20 && i == 16) || (cel.Text.Length > 20 && i == 17) ||
(cel.Text.Length > 20 && i == 18))
cel.Text = cel.Text.Substring(0, 20) + "...";
cel.ToolTip = s;
}
foreach (GridViewRow row in grid_Emp.Rows)
{
foreach (TableCell cell1 in row.Cells)
{
cell1.HorizontalAlign = HorizontalAlign.Left;
}
}
}
#endregion
}
{
#region EditableAndUnEditableRows
Boolean b1 = Convert.ToBoolean((drview[19])); // if (drview[5].ToString() == "True")
if (b1 == true)
{
e.Row.Enabled = false;
// e.Row.BackColor = System.Drawing.Color.LightSlateGray;
}
else if (b1 == false)
{
e.Row.Enabled = true;
}
#endregion
#region HorizontalAlignLeft
if (e.Row.RowType == DataControlRowType.DataRow || e.Row.RowType == DataControlRowType.Header)
{
foreach (TableCell cel in e.Row.Cells)
{
i++;
string s = cel.Text;
if ((cel.Text.Length > 20 && i == 1) || (cel.Text.Length > 20 && i == 2) || (cel.Text.Length > 20 && i == 3) ||
(cel.Text.Length > 20 && i == 4) || (cel.Text.Length > 20 && i == 5) || (cel.Text.Length > 20 && i == 6) || (cel.Text.Length > 20 && i == 7) || (cel.Text.Length > 20 && i == 8) ||
(cel.Text.Length > 20 && i == 9) || (cel.Text.Length > 20 && i == 10) || (cel.Text.Length > 20 && i == 11) || (cel.Text.Length > 20 && i == 12) ||
(cel.Text.Length > 20 && i == 13) || (cel.Text.Length > 20 && i == 14) || (cel.Text.Length > 20 && i == 15) || (cel.Text.Length > 20 && i == 16) || (cel.Text.Length > 20 && i == 17) ||
(cel.Text.Length > 20 && i == 18))
cel.Text = cel.Text.Substring(0, 20) + "...";
cel.ToolTip = s;
}
foreach (GridViewRow row in grid_Emp.Rows)
{
foreach (TableCell cell1 in row.Cells)
{
cell1.HorizontalAlign = HorizontalAlign.Left;
}
}
}
#endregion
}
}
}
--------
In the line - Boolean b1 = Convert.ToBoolean((drview[19])) - The system is throwing an error - Object reference not set to an instance....
-------
Please guide me where I am going wrong.
There are 600 records total in the database now.
Upendra Pratap ShahiPosted Jul 7, 2015, 2:06 AM
Riddhi ValechaPosted Jul 7, 2015, 1:55 AM
Riddhi ValechaPosted Jul 3, 2015, 7:42 AM
Upendra Pratap ShahiPosted Jul 3, 2015, 2:42 AM
Riddhi ValechaPosted Jul 3, 2015, 2:06 AM
Saroj Kumar SahuPosted Jun 16, 2015, 5:17 AM