You must Sign In to post a response.
  • Category: Silverlight

    Datagrid row and column value

    Hi ,

    I have a datagrid with 3 rows and 3 cols.I am populating some values by applying some condition in 1st row last cell and 2nd row last cell as a result 3rd row last cell is empty.

    Now, I need to write some logic in 3rd row last colum:

    say 1 st row last cell value is A.
    2nd row last cell value is B.

    Now I have to write C -(A+B) in 3rd row last cell value of datagrid.

    Please help .


    Regards,
  • #753560
    Hi Ayesha,

    Just see this code. Might be it will help you.

    for (int i = 0; i < ProductGridView.Rows.Count; i++)
    {
    ProductGridView.Rows[i].Cells[2].Value = Convert.ToInt32(ProductGridView.Rows[i].Cells[0].Value.ToString()) + Convert.ToInt32(ProductGridView.Rows[i].Cells[1].Value);
    }

    still if you facing the problem let me know.
    Nirav Lalan,
    IT has no ends.

    Regards,
    Nirav Lalan
    DNS Gold Member
    "Failure is the path of least persistence"

  • #753565
    Hi,

    If you want to perform some calculation based on some condition on your datasource control then refer below sample this might be helpful to you.


    int a=0,b=0;
    protected void GV_OnRowDataBound(object sender, GridViewRowEventArgs e)
    {
    if(e.Row.RowType==DataControlRowType.DataRow)
    {
    int index=e.Row.RowIndex;
    if(index==0)
    {
    a=((Label)e.Row.FindControl("lblval")).Text;
    }
    else if(index==1)
    {
    b=((Label)e.Row.FindControl("lblval")).Text;
    }
    else if(index==2)
    {
    c=a+b;
    ((Label)e.Row.FindControl("lblval")).Text=c.ToString();
    }
    }
    }


    Try something like above to achieve your goal..

    Hope this will helpful to you to achieve your goal..

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/

  • #753574
    Hi,
    Whatever operation you wanted to do it on the gridview can be done on the OnRowDataBound event. If you are new to datagrid then I would suggest you to go through the tutorials.
    csharp.net-informations.com/datagridview/csharp-datagridview-tutorial.htm
    dotnetperls.com/datagridview-tutorial


    Regards,
    Asheej T K

  • #753589
    Here is code snippet for color Datagrid row and column value in silverlight


    void Studentdatagrid_LoadingRow(object sender, DataGridRowEventArgs e)
    {
    EnrollRef.StudentDetail slist = e.Row.DataContext as EnrollRef.StudentDetail;
    FrameworkElement el;
    el = this.Studentdatagrid.Columns[1].GetCellContent(e.Row);
    DataGridCell changeCell = GetParent(el, typeof(DataGridCell)) as DataGridCell;
    SolidColorBrush brush = new SolidColorBrush(Colors.Black);
    if (changeCell != null)
    {
    if (slist.value > 0)
    {
    brush = new SolidColorBrush(Colors.Green);
    }
    else if (slist.value < 0)
    {
    brush = new SolidColorBrush(Colors.Red);
    }
    changeCell.Foreground = brush;
    }

    }


  • Sign In to post your comments