本文介绍了数据绑定方法(如Eval(),XPath()和Bind())只能在数据绑定控件的上下文中使用。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
亲爱的朋友,
我在网格视图中实现代码时遇到了一些问题。当我通过编码对gridview控件进行数据绑定时产生错误。产生以下错误:
数据绑定方法,如Eval(),XPath()和Bind()只能在数据绑定控件的上下文中使用。
.cs代码是: -
Dear friend,
I have some problem when implementing the code in grid view.The error produce when i am databind the gridview control by coding.The following error are produced :
"Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control."
.cs code is :-
double total = 0;
db = new MCTAdminDataContext();
var advance = (from t in db.Transactions
where t.IsChecked && t.IsConfirmed == true
select new
{
TransactionID = t.TransactionID,
RecordingDate = t.CreationDate,
TransactionDate = t.TransactionDate,
CreditAccount = t.CreditAccount,
DebitAccount = t.DebitAccount,
AccountNo = getAccountNo(t.AccountNo),
Type = t.TransactionType,
From = getName(t.DebitAccount, t.SpecifiedName, t.ClientOrCompanyName),
To = getName(t.CreditAccount, t.SpecifiedName, ""),
Amount = t.Amount,
For = t.Description,
Project = getProject(t.ProjectID),
Head = getHead(t.HeadID),
CompanyID = t.CompanyID
}).ToList();
advance = (advance.Where(a => a.CompanyID.Equals(Session[SessionController.Session_CompanyId]))).ToList();
if (!string.IsNullOrEmpty(drpEmployee.SelectedValue) && drpEmployee.SelectedValue != "0" && drpEmployee.SelectedValue != "--Select--")
{
advance = (from a in advance
where a.CreditAccount == Convert.ToInt64(drpEmployee.SelectedValue)
select a).ToList();
total = advance.Sum(a => Convert.ToDouble(Convert.ToString(a.Amount).Replace(",", string.Empty)));
}
else
{
advance = (from a in advance
where a.Type.Contains("Receipt") || a.Type.Contains("Advance")
select a).ToList();
}
grdAdvance.DataSource = advance;
grdAdvance.DataBind();->error find here
return total;
.aspx代码: -
.aspx code :-
<asp:LinkButton runat="server" ID="Delete" OnClientClick="return confirm('Are you sure?');"
Text='Delete' CommandArgument='<%#Eval("TransactionID" %>'---->Error produced here
CommandName="lnkDelete"></asp:LinkButton>
请尽快解决这个问题..
感谢先进!!
Please solve this problem as soon as possible..
Thanks in advanced !!
推荐答案
.gv_hide_column
{
display: none;
}
<pre lang="HTML"><pre lang="xml"><asp:BoundField DataField="<pre lang="xml">TransactionID&quot; HeaderText=&quot;<pre lang="xml">TransactionID&amp;quot; ItemStyle-CssClass=&amp;quot;gv_hide_column&amp;quot;
HeaderStyle-CssClass=&amp;quot;gv_hide_column&amp;quot; /&amp;gt;
&amp;lt;pre lang=&amp;quot;xml&amp;quot;&amp;gt;&amp;amp;lt;asp:ImageButton ID=&amp;amp;quot;imgbtnDelete&amp;amp;quot; Text=&amp;amp;quot;Delete&amp;amp;quot; runat=&amp;amp;quot;server&amp;amp;quot; OnClick=&amp;amp;quot;imgbtnDelete_Click&amp;amp;quot;
&amp;lt;b&amp;gt;RowIndex=&amp;amp;#39;&amp;amp;lt;%# Container.DisplayIndex %&amp;amp;gt;&amp;amp;#39;&amp;lt;/b&amp;gt; ImageUrl=&amp;amp;quot;~/Images/DeleteIcon.png&amp;amp;quot; ToolTip=&amp;amp;quot;Delete this user&amp;amp;quot;
Height=&amp;amp;quot;16px&amp;amp;quot; Width=&amp;amp;quot;16px&amp;amp;quot; /&amp;amp;gt;&amp;lt;/pre&amp;gt;&lt;/pre&gt;</pre></pre>
<pre lang="cs">protected void imgbtnDelete_Click(object sender, EventArgs e)
{
try
{
ImageButton vImgbtnDeleteToGetRowIndex = sender as ImageButton;
int vRowIndex = Convert.ToInt32(vImgbtnDeleteToGetRowIndex.Attributes["RowIndex"]);
int vUserId = Convert.ToInt32(gvTestEditSequence.DataKeys[vRowIndex].Values["TransactionID"].ToString());
这篇关于数据绑定方法(如Eval(),XPath()和Bind())只能在数据绑定控件的上下文中使用。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!