Binding only one column
Setting text property of Tabs as follows:
In the code below , GetQuesType() returns a complete QuesType named Table so the Tabs generated by the code below are like equal to the no. of records in the table. What I want is that ONLY QuesType column be binded to the Tabs. What should I change in my code?
aspx page:
**<div id="div1" runat="server">
<telerik:RadTabStrip ID="RadTabStrip1" runat="server" MultiPageID="RadMultiPage1">
</telerik:RadTabStrip>
<telerik:RadMultiPage ID="RadMultiPage1" runat="server" Width="100%">
<telerik:RadPageView ID="pv1" runat="server" Selected="true">
</telerik:RadPageView>
</telerik:RadMultiPage>
</div>**
I have followed this example:
http://mono.telerik.com/TabStrip/Examples/PopulatingWithData/DynamicCreation/DefaultCS.aspx
{EDIT}
Modified the method as follows:
private void CreateRootTab(DataSet ds)
{
for (int i = 0; i < ds.Tables[0].Columns.Count; i++)
{
var tab = new RadTab();
tab.Text = (string) ds.Tables[0].Rows["QuesType"].ItemArray[i];//PROBLEM AREA
RadTabStrip1.Tabs.Add(tab);
}
}
Now it says: The best overloaded method match for 'System.Data.DataRowCollection.this[int]'开发者_运维技巧 has some invalid arguments
How else should I bind the tabs with QuesType column?
ok it should have been this:
tab.Text = ds.Tables[0].Rows[0]["QuesType"].ItemArray[i].ToString();
Now its giving error on itemArray
'object' does not contain a definition for 'ItemArray' and no extension method 'ItemArray' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)
The default type returned by a row column is Object
. You need to cast the column returned by this statement...
ds.Tables[0].Rows[0]["QuesType"]
...to the appropriate type before calling ItemArray[0]
. A quick and dirty way to do this is...
tab.Text = ((QuesType)ds.Tables[0].Rows[0]["QuesType"]).ItemArray[0];
However, a more robust, and less error-prone solution would be...
if (ds.Tables.Count > 0)
{
var table = ds.Tables[0];
var columnName = "QuesType";
if (table.Rows.Count > 0 && table.Columns.Contains(columnName))
{
var tableRow = table.Rows[0];
var quesType = tableRow.Field<QuesType>(columnName);
if (quesType != null && quesType.ItemArray.Count() > 0)
{
tab.Text = quesType.ItemArray[0];
}
}
}
I hope that helps!
精彩评论