How do i implement a type function
<p>I have created a function which return the value according to the specified type.</p>

<p>Code:</p>

<pre><code>private T FindCellValue&lt;T&gt;(GridViewRow grdRow, string cntName)
        {
            var currColType = grdRow.FindControl(cntName);
            object val = currColType;
            if (currColType is HiddenField)
            {
                val = ((HiddenField)currColType).Value;
            }
            if (currColType is TextBox)
            {
                val = ((TextBox)currColType).Text;
            }
            if (currColType is HtmlInputText)
            {
                val = ((HtmlInputText)currColType).Value;
            }
            if (currColType is DropDownList)
            {
                var selectedItem = ((DropDownList)currColType).SelectedItem;
                val = new string[] { selectedItem.Text, selectedItem.Value };
            }
            if (currColType is RadDateTimePicker)
            {
                val = ((RadDateTimePicker)currColType).SelectedDate;
            }

            if (!(val is Control || val is WebControl || val is HtmlInputControl) &amp;&amp; string.IsNullOrEmpty(Convert.ToString(val)))
            {
                return default(T);
            }
            return (T)val;
        }
</code></pre>

<p>This code fails many time while typecasting . How do i implement it efficient way? </p>
