gpt4 book ai didi

asp.net - 如何将数据库字段值绑定(bind)到 gridview 中的隐藏字段

转载 作者:行者123 更新时间:2023-11-30 23:39:03 24 4
gpt4 key购买 nike

我使用以下方法将表中的字段绑定(bind)到 gridview 中的隐藏字段,但出现错误,因为 System.Data.DataRowView' 不包含名为“AccountType”的属性。

我是这样分配的

<asp:TemplateField>
<ItemTemplate>
<asp:HiddenField ID="hdnAccntType" runat="Server" Value='<%#Eval("AccountType") %>' />
</ItemTemplate>
</asp:TemplateField>

它是正确的还是我必须做任何更正?

我的存储过程:

CREATE DEFINER=`root`@`%` PROCEDURE `uspGetEmployeeBankDate`(_EmpID INT(11),
_BankTypeID varchar(10),_AccountType varchar(10))
BEGIN
select EmpID,BankTypeID,DATE_FORMAT(StartDate, '%Y-%m-%d')
as StartDate,DATE_FORMAT(EndDate, '%Y-%m-%d') as EndDate
from tblemployeebankdata where EmpID=_EmpID and BankTypeID=_BankTypeID
and AccountType=_AccountType;

END

示例代码

       if (mlocal_ds.Tables[0].Rows.Count != 0)
{
foreach (DataRow drRow in mlocal_ds.Tables[0].Rows)
{
if (drRow["BankTypeID"].ToString() == "DbalC")
{
pnlGrid.Visible = false;
grdBank.Visible = true;
//grdData.Visible = false;

strEmpID = HiddenField1.Value;
string AccntType = drRow["AccountType"].ToString();
string strBankTypeID = drRow["BankTypeID"].ToString();
string mlocal_strStoredProcName = StoredProcNames.tblEmployeeBankdetails_uspEmployeeBankdetailsDate;
mlocal_ds = new DataSet();
oEmployee.SelectId(out mlocal_ds, mlocal_strStoredProcName, strEmpID, strBankTypeID,AccntType); // here the stored procedure is executed
grdBank.DataSource = mlocal_ds;
grdBank.DataBind();
pnlChckAcc.Visible = false;
pnlPrimary.Visible = false;
pnlSecond.Visible = false;
pnlSecondary.Visible = false;
pnlFirst.Visible = false;
pnlEditInfo.Visible = false;
break;
}

我的 GridView

     <asp:GridView ID="grdBank" runat="server" AutoGenerateColumns="False" CellPadding="4"
CssClass="grid" ForeColor="#333333" GridLines="None" Width="349px" Visible="False">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:RadioButton ID="rdbtnBank" runat="server" AutoPostBack="true" OnCheckedChanged="rdbtnBank_CheckedChanged" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:HiddenField ID="hdnAccntType" runat="Server" Value='<%# DataBinder.Eval(Container.DataItem, "AccountType") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="EmpID" HeaderText="EmpID">
<ItemStyle CssClass="intitalitefname" />
</asp:BoundField>
<asp:BoundField DataField="BankTypeID" HeaderText="BankTypeID">
<ItemStyle CssClass="intitalitefname" />
</asp:BoundField>
<asp:BoundField DataField="StartDate" HeaderText="Start Date">
<ItemStyle CssClass="intitalitefname" />
</asp:BoundField>
<asp:BoundField DataField="EndDate" HeaderText="End Date">
<ItemStyle CssClass="intitalitefname" />
</asp:BoundField>
</Columns>
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#999999" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<EmptyDataTemplate>
nodata to display
</EmptyDataTemplate>
</asp:GridView>

最佳答案

正如 Muhammed Akhtar 所说,您的原始数据源不包含 AccountType 字段,因此您无法将其绑定(bind)到任何内容

您需要将存储过程更改为:

CREATE DEFINER=`root`@`%` PROCEDURE `uspGetEmployeeBankDate`(_EmpID INT(11),

_BankTypeID varchar(10),_AccountType varchar(10))
BEGIN
select AccountType, EmpID,BankTypeID,DATE_FORMAT(StartDate, '%Y-%m-%d')
as StartDate,DATE_FORMAT(EndDate, '%Y-%m-%d') as EndDate
from tblemployeebankdata where EmpID=_EmpID and BankTypeID=_BankTypeID
and AccountType=_AccountType;

END

我修改的就在您的“选择”的开头,现在包括 AccountType 字段。如果您不在原始选择中包含此字段,则它不会包含在您返回的数据源中,这反过来意味着您无法绑定(bind)它

希望对你有帮助

戴夫

关于asp.net - 如何将数据库字段值绑定(bind)到 gridview 中的隐藏字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5038566/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com