Unable to cast object of type 'System.String' to type 'System.Data.DataRowView'

Hi, I am having this problem: Unable to cast object of type 'System.String' to type 'System.Data.DataRowView'

I have two repeaters: One is for a list of terms and the other show the definition. What I am trying to do is, highlight the selected term.

Here is the relevant code which has this error:

private Color SetButtonBackColor(object dataItem)
 Response.Write("<br />In SetButtonBackColor Function");
 Response.Write("<br>dataItem in SetColor is: " +(string)((DataRowView)dataItem)["TermIndex"]);
 string _initial =  (string) ((DataRowView)dataItem)["TermIndex"];

 Response.Write("<br>Initial is: "  + _initial + "<br />ViewState is " + ViewState["TermIndex"]);

 if (_initial == (string) ViewState["TermIndex"])
  return Color.Red;
 return Color.Blue;

private void BindTerm(object term)
    //create a connection to the db
    OleDbConnection oCxn = dbConnectDataDictionary();

 ViewState["TermIndex"] = term;
 Response.Write("<br>term in BindTerm is: " + term);
 Response.Write("<br>ViewState in BindTerm is: " + ViewState["TermIndex"]);
// FillGlossary(ref oCxn, TermsQuery, ref GlossaryRepeater, term);

 //Data set Two 
 DataSet _data3 = new DataSet();
 string _Query = "SELECT[attribute name] AS TermIndex, [attribute type], [source for raw data], definition FROM [Attributes] WHERE [Attribute Name] like '{0}'";
 string _cmdTerm = String.Format(_Query, term);

 OleDbDataAdapter _adapter3 = new OleDbDataAdapter(_cmdTerm, oCxn);


 GlossaryRepeater.DataSource = _data3.Tables[0].DefaultView;

 //close the connection
 dbRelease (ref oCxn);
public void showTerm(Object sender, RepeaterCommandEventArgs  e)
<asp:repeater runat="server"  id="Glossary"  OnItemCommand = "showTerm">
  <div style="background-color:7B84BE;color:white;height:20px;">&nbsp;<big><b><%# SetHeader() %></b></big></div>
  <div style="background-color:#F3F3FB;height:400px;overflow:auto; padding: 10px; line-height:200%; font-size: x-small">

  <asp:LinkButton id="lb" runat="server"
  ForeColor='<%# SetButtonBackColor(Container.DataItem)%>'
  Text='<%# DataBinder.Eval(Container.DataItem,"[TermIndex]")%>' 
  CommandName ='<%# DataBinder.Eval(Container.DataItem,"[TermIndex]")%>' />
  <br />
  <div style="background-color:7B84BE; color:white;height:20px;">&nbsp;<b><%# SetFooter() %></b></div>

Does anybody know how to make it work?

Thank you.

8/2/2005 7:10:50 PM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

1 Replies

Similar Articles

[PageSpeed] 11
Get it on Google Play
Get it on Apple App Store

The error occurs at this line: string _initial =  (string) ((DataRowView)dataItem)["TermIndex"];
8/2/2005 8:42:59 PM

Web resources about - Unable to cast object of type 'System.String' to type 'System.Data.DataRowView' - asp.net.presentation-controls

Resources last updated: 2/24/2016 11:01:21 AM