This is a migrated thread and some comments may be shown as answers.

How to Convert Gridview to Radgrid

1 Answer 137 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Coolbudy
Top achievements
Rank 1
Coolbudy asked on 04 Jul 2013, 07:35 AM
  Below is the gridview rowcommand code which i want to convert in radgrid itemdatabound any budy have solution

protected void Gridviiew_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            try
            {
                if (e.Row.RowType == DataControlRowType.Header)
                {
                    dtTotalDuration = Convert.ToDateTime("01/01/1900");
                    dtTotalTimeSpent = Convert.ToDateTime("01/01/1900");
                }
                else if (e.Row.RowType == DataControlRowType.DataRow)
                {
                    Int32 intRow = e.Row.RowIndex + 1;

                    int intSeconds;
                    string strValue;
                    string strHtml;

                    //strHtml = "javascript:var w=window.showModalDialog('Course.aspx?ChapterNum=" + intRow.ToString() + "', null, 'dialogHeight=700px; dialogTop=75px; dialogLeft=250px; dialogWidth=800px; edge=Raised; center=No; help=Yes; resizable=no; status=no; scroll=yes');";
                    strHtml = "javascript:var w=openCourse('" + intRow.ToString() + "', '" + Session["CID"].ToString() + "');";
                     //   e.Row.Cells[4].Attributes.Add("OnClientClick", "function_Name()");

                    //Add New
                    string strhtmlnew1 = "javascript:RadWindowOpenCourse('" + intRow.ToString() + "', '" + Session["CID"].ToString() + "');";
                    e.Row.Cells[4].Attributes.Add("OnClick", "javascript:RadWindowOpenCourse('" + intRow.ToString() + "','" + Session["CID"] + "');return false;");
                   
                    strValue = DataBinder.Eval(e.Row.DataItem, "Course_Duration").ToString();
                    intSeconds = clsCommonData.MyInt32Convert(strValue.Substring(0, 2)) * 3600 + clsCommonData.MyInt32Convert(strValue.Substring(3, 2)) * 60 + clsCommonData.MyInt32Convert(strValue.Substring(6, 2));
                    dtTotalDuration = dtTotalDuration.AddSeconds(Convert.ToDouble(intSeconds));

                    strValue = DataBinder.Eval(e.Row.DataItem, "Customer_Duration").ToString();
                    intSeconds = clsCommonData.MyInt32Convert(strValue.Substring(0, 2)) * 3600 + clsCommonData.MyInt32Convert(strValue.Substring(3, 2)) * 60 + clsCommonData.MyInt32Convert(strValue.Substring(6, 2));
                    dtTotalTimeSpent = dtTotalTimeSpent.AddSeconds(Convert.ToDouble(intSeconds));
                }
                else if (e.Row.RowType == DataControlRowType.Footer)
                {
                    e.Row.Cells[1].Text = dtTotalDuration.ToString("HH:mm:ss");
                    e.Row.Cells[2].Text = dtTotalTimeSpent.ToString("HH:mm:ss");
                }
            }
            catch (Exception ex)
            {
                if (ex.Message.Substring(0, 56) != "Specified argument was out of the range of valid values.")
                {
                    clsErrorLogData.LogError("Content", "Gridviiew_RowDataBound", ex.Source + "_" + Common_App.MyString(Session["CID"]), ex.Message, "");
                }
            }
        }

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 05 Jul 2013, 08:31 AM
Hi,

Please try the following code snippet.

C#:
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
    try
    {
        if (e.Item is GridHeaderItem)
        {
            GridHeaderItem header = (GridHeaderItem)e.Item;//Access the header item
            //Your code
        }
        else if (e.Item is GridDataItem)
        {
            GridDataItem data = (GridDataItem)e.Item;//Access data item
            //Your code
        }
        else if (e.Item is GridFooterItem)
        {
            GridFooterItem footer = (GridFooterItem)e.Item;//Access the footer
            //Your code
        }
    }
    catch (Exception ex)
    {
        //Your code
    }
}

Thanks,
Princy
Tags
General Discussions
Asked by
Coolbudy
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or