.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Gridview icw XMLDatasource :Databinding methods such as Eval(), XPath(), and Bind() can only be used

Posted By:      Posted Date: September 27, 2010    Points: 0   Category :ASP.Net

I want to get the value of an xpath expression in rowdatabound event. But I get:
Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.

<asp:GridView ID="gvSearchResults"  AutoGenerateColumns="False" DataSourceID="XMLDS" runat="server">
    Rating:  <%# XPath("float[@name=""location_rating""]")%>

<asp:XmlDataSource EnableCaching="False" XPath="response/result/doc" ID="XMLDS" runat="server"></asp:XmlDataSource>

Protected Sub gvSearchResults_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvSearchResults.RowDataBound
    Dim value As String = XPath("float[@name=""location_rating""]")
End Sub

View Complete Post

More Related Resource Links

Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databou


within .aspx I have gridview I trying to hide link called Guide based on country.I am getting value of country from stored procedure.Once I get value of country I pass it to method called CountryConfigs which takes guidelink and countrycode as parameter.Based on parameter passed it will show and hide guide link.



How to bind GridView and DropDownList controls using DataTable object

In .net framework 2.0, you can load a DataTable in memory by consuming a data source using a DataReader. In this version you will find the flexibility in accessing the DataReader means write access code once and use again and again using DataReader. To see the functionality of DataTable consider an example that is created using VS2005.

Change data on gridview bind


Hi there,

Simple little problem. i have a gridview that shows products assigned to a customers job. They are displayed in exVAT prices. To make it easier i want to show the inc VAT prices. How can i add VAT to 1 column in this table?

xmldatasource and xpath expression evaluation

Hi, I am working with XMLdatasource and trying to consume a XML file. Now problem is there are scenarios when a link is not available in the xml file. Like in the e.g. below: <a href='<%# XPath("link") %>' >  </a>  say "link" can or cannot be there in the file. Now when "link" is missing, this expression throws exception. How can I handle this exception so that it continues loading page normally or can I check "link" existence somehow? Thanks.

Showing Solr XML results in gridview using xmldatasource

I have the XML below, generated by Apache Solr.I want to assign the results (2 <doc>nodes in this case) to a gridview using an XML datasource.<response>-<lst name="responseHeader">    <int name="status">0</int>    <int name="QTime">0</int>    <lst name="params">        <str name="facet">true</str>        <str name="fl">        id,title,city,score,location_rating,introtext,location_rating_total,themes,features,official,services        </str>        <str name="indent">on</str>        <str name="start">0</str>        <str name="q">*:*</str>        <arr name="facet.field">            <str>province_raw</str>            <str>services_raw</str>            <str>themes_raw</str>           &

XMLDatasource with gridview: only first result is showing

My gridview is showing only the first result from the data I have assigned to the XMLDatasource.This is this XML:<response>-<lst name="responseHeader">    <int name="status">0</int>    <int name="QTime">0</int>    <lst name="params">        <str name="facet">true</str>        <str name="fl">        id,title,city,score,location_rating,introtext,location_rating_total,themes,features,official,services        </str>        <str name="indent">on</str>        <str name="start">0</str>        <str name="q">*:*</str>        <arr name="facet.field">            <str>province_raw</str>            <str>services_raw</str>            <str>themes_raw</str>            <str>features_raw</st

Bind List&lt;&gt; to GridView

Can any body help how to update list through gridview

Is it best to use Eval or Bind in a databound control?

I have a repeater I've databound with a generic arraylist from a LINQ query (.ToList() )  in the code behind.  I was using   <%# Bind("FirstName")%> but noticed  <%# Eval("FirstName")%> works just as well.    Is it better to use Eval or Bind?  or does it depend on the situation?        

Nested Gridview and databinding

protected void grdClientPayments_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { GridView gv = (GridView)e.Row.FindControl("grdPayments"); SqlDataSource dbSrc = new SqlDataSource(); dbSrc.ConnectionString = NFMData.DB.GetDBConn(); dbSrc.SelectCommand = "SELECT APR.PaymentID, APR.AdID, PaymentAmount, PaymentDate, CheckNo, APR.Comments " + "FROM AdPaymentReceived APR " + "LEFT OUTER JOIN ISRPayment_Payments IPP ON IPP.PaymentID = APR.PaymentID " + "WHERE ISNULL(IPP.Amount,0) <= 0 AND APR.AdID = " + ((DataRowView)e.Row.DataItem)["AdID"].ToString(); gv.DataSource = dbSrc; gv.DataBind(); foreach (GridViewRow gvRow in gv.Rows) { if (gvRow.RowType == DataControlRowType.DataRow) { decimal PaymentAmount = (decimal)((DataRowView)gvRow.DataItem)["PaymentAmount"]; } } }   So basically what I'm trying to do is do some calculation on the rows in the sub-grid based on some values in the main grid.

Build chart bar with asp.net (bind from gridview)

Build chart bar with asp.net (bind from gridview)Please guide to there with vb code.

Finding underlying Eval or Bind column name from TemplateField

I need to be able to get the underlying column name from each TemplateField in my GridView. So I have something like:<asp:TemplateField HeaderText="Current Market Event" SortExpression="current_market_event"> <ItemTemplate> <asp:Label ID="Label2" runat="server" Text='<%# Eval("current_market_event") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> I see how to do this with a BoundField quiet easily: BoundField.DataField. Is there any way to do this for a TemplateField?

read delimited files into a datatable and bind to a gridview

I have a delimted file , like a csv file but the delimters are # and not ,I assume I would use SqlConnection and SqlDataAdapterSo for a csv file what is the sequence to read in for example c:\data\demo.csvWhat would the connection string be.Also can you specifiy a different delimiter.The code below is what I assume it would possibly look likea although its only a frst guess. ThanksJim Dim connectionString As String = "Data Source=localhost;Initial Catalog=master;Integrated Security=true;" Dim con As New SqlConnection(ConfigurationManager.ConnectionStrings("Northwind_ConnectionString").ConnectionString) Dim str As String = "SELECT * FROM Employees" Dim cmd As New SqlCommand(str, con) Dim da As New SqlDataAdapter(cmd) Dim dt As New DataTable() da.Fill(dt) GridView1.DataSource = dt GridView1.DataBind()

gridview datakeynames with xmldatasource

I have this:<asp:GridView ID="gvSearchResults" PageSize="10" AutoGenerateColumns="false" DataSourceID="XMLDS" runat="server">    <Columns>        <asp:TemplateField>            <ItemTemplate>                <i>Name <%# XPath("str[@name=""introtext""]")%></i><asp:Button ID="ltbnCompare" Text="Compare" CommandName="Compare" CommandArgument='<%# XPath("str[@name=""id""]")%>' runat="server" />            </ItemTemplate>        </asp:TemplateField>    </Columns>    </asp:GridView>    <asp:XmlDataSource EnableCaching="false" XPath="response/result/doc" ID="XMLDS" runat="server"></asp:XmlDataSource>Now in the gvSearchResults_OnRowCommand I want to read the datakeynames for a row in which a button was clicked.But I need to reed several datakeynames, such as id, img and title.How can I put these

How to Bind Selective Columns from Stored Proc to Gridview using the entity framework


Hi Guys,

I have this entity model>> http://img840.imageshack.us/img840/306/schemaj.jpg and I would like to bind  a list  which consists of: employee's

  • emloyee_firstname(employees table) + employee_lastname(employees table)
  • employee's extension(employee_extension table)
  • deparment name(departments table)

to my gridview. I already created my stored procedure

    Concat(employees.employee_firstname," ",employees.employee_lastname) as name
    , extensions.extension_number
    , departments.department_description
    INNER JOIN employees 
        ON (employee_extensions.employee_id = employees.employee_id)
    INNER JOIN extensions 
        ON (employee_extensions.extension_id = extensions.extension_id)
    INNER JOIN departments 
        ON (employees.department_id = departments.department_id)

But my problem is, i don't know how to bind it since i don't have an entity that contains the employee's name, extension# and departments name. Do I need to create a custom class that consists of said columns? or is their a proper way to do this? I'

Bind listbox to gridview on client side



I have a list box (that uses a SQlDataSource) that has a list of jobs. I have a grid view (that also uses a SQLDataSource) that has the items used in each job. I want to bind the list box value to the gridview on the client side, i.e. when the user clicks on a different job in the list view I want the grid to show the items for that job.

Also, at formload I want the gridview to show the details of the first job on the listview.

Please let me know how I can do this in the aspx page.


- Sankaran

Bind a GridView to a DataTable (in Viewstate) with full in-line CRUD


Hello fellow devs!

I need a bit of help with a scenario. I am working on a web application that requires huge amounts of data to be Added, Deleted, and Updated. The data entry forms are divided into logical groups through Multiviews. All the information is saved when the mighty Finish button is pressed. The current setup (previous developer) does not allow me to use transactions. Therefore, if I am to save a new Courier to the database, I need to add his/her Distance and Rate info. In addition, I need to add his/her Banned Areas info (Area Name, Post Code).

This is where it gets interesting. Obviously, the DistamceAndRate table and the BannedArea table in my SQL Server will have the CourierID as a foreign key. Since I'm going to save the Courier as well as the Rates and Areas info in one go, I cannot have the newly created CourierID before. Therefore, I cannot bind my Grids for Distance + Rates and Banned Areas directly to database.
What I am doing is creating two DataTables and managing them in Viewstate through properties as follow:

        private DataTable TableDistancesAndRates {
            get {
                object objTableDistancesAndRates = ViewState["vTableDistancesAndRates"];

                if (objTableDistancesAndRates!=null) {
                    return (DataTable)objTableD

how to postpone gridview databinding


I have a GV & a FV both linked to same sqldatasource.

When a GV row is clicked, the FV becomes available for editing the row but the GV as a result is reduced to only that row. I want to GV to remain showing all rows. I am using GV selected_index event to invoke "SqlDataSource1.SelectCommand= " blah blah"




ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend