Asp.net 从Gridview获取SQLDataSource更新参数
我试图从gridview中获取更新的参数,但它是我不希望显示的ID列。如果在boundfield中显示数据,则效果良好,但如果将可见性设置为false,则参数将不再发送到更新存储过程。似乎没有可以放入gridview的hiddenfield列 我试图通过代码隐藏设置参数,但我不确定如何访问我想要的数据以下代码不起作用(它将参数设置为nothing)Asp.net 从Gridview获取SQLDataSource更新参数,asp.net,vb.net,webforms,Asp.net,Vb.net,Webforms,我试图从gridview中获取更新的参数,但它是我不希望显示的ID列。如果在boundfield中显示数据,则效果良好,但如果将可见性设置为false,则参数将不再发送到更新存储过程。似乎没有可以放入gridview的hiddenfield列 我试图通过代码隐藏设置参数,但我不确定如何访问我想要的数据以下代码不起作用(它将参数设置为nothing) Protected Sub grvFacilityDisciplineBillingRate_RowUpdating(ByVal sender As
Protected Sub grvFacilityDisciplineBillingRate_RowUpdating(ByVal sender As Object, ByVal e As GridViewUpdateEventArgs) Handles grvFacilityDisciplineBillingRate.RowUpdating
Dim row As GridViewRow = grvFacilityDisciplineBillingRate.Rows(e.RowIndex)
sqlDisciplineBillingRate.UpdateParameters("Facility_ID").DefaultValue = CInt(row.DataItem("Facility_ID"))
sqlDisciplineBillingRate.UpdateParameters("Discipline_ID").DefaultValue = CInt(row.DataItem("Discipline_ID"))
End Sub
这是前端,显示了两个ID列,这不是我想要的
<asp:SqlDataSource ID="sqlDisciplineBillingRate" runat="server" DataSourceMode="DataSet" SelectCommandType="StoredProcedure" SelectCommand="SP_Facility_DisciplineBillingRates" UpdateCommandType="StoredProcedure" UpdateCommand="SP_DiscplineBillingRate_Update" ConnectionString="<%$ ConnectionStrings:Trustaff_ESig2 %>">
<SelectParameters>
<asp:Parameter Name="Facility_ID" DbType="Int32" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="Facility_ID" DbType="Int32" />
<asp:Parameter Name="Discipline_ID" DbType="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
<asp:GridView ID="grvFacilityDisciplineBillingRate" runat="server" DataSourceID="sqlDisciplineBillingRate" DataKeyNames="DisciplineBillingRate_ID" AutoGenerateColumns="false" AllowSorting="true" AllowPaging="false" AutoGenerateEditButton="true" CssClass="gridview">
<EmptyDataTemplate>
There were no discipline billing rates for this facility.
</EmptyDataTemplate>
<Columns>
<asp:BoundField DataField="Name" HeaderText="Discipline" SortExpression="Name" ReadOnly="true" />
<asp:BoundField DataField="BillingRate" HeaderText="Billing Rate" SortExpression="BillingRate" />
<asp:BoundField DataField="Facility_ID" HeaderText="Facility_ID" SortExpression="Facility_ID" InsertVisible="false" />
<asp:BoundField DataField="Discipline_ID" HeaderText="Discipline_ID" SortExpression="Discipline_ID" />
</Columns>
</asp:GridView>
该设施没有专业计费费率。
尝试使用模板字段和标签控件,并通过设置visible=“false”隐藏它们
如果您不希望使用ID列,可以取消使用模板化字段。并且仍然可以使用datakeynames属性访问它尝试使用模板字段并使用标签控件,然后通过设置visible=“false”将其隐藏
如果您不希望使用ID列,您可以取消使用模板字段。并且仍然可以使用datakeynames属性访问它您只需设置例如datakeynames=“Facility\u ID,规程\u ID”当使用GV的更新和删除功能时,SqlDataSource将为您解决这个问题。您只需设置DataKeyNames=“Facility\u ID,规程\u ID”当使用GV的更新和删除功能时,SqlDataSource会帮你解决这个问题。谢谢!我不知道我可以为它添加更多的值,尽管现在看它是名称而不是名称,哈哈。谢谢!我不知道我可以为它添加更多的值,尽管现在看它是名称而不是名称,哈哈。
<asp:TemplateField HeaderText="College">
<ItemTemplate>
<asp:Label ID="lbl_Title" runat="server" text='<%# Bind("Title") %>' visible="false"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
If gvrow.RowType = DataControlRowType.DataRow Then
Dim label1 As Label = DirectCast(gvrow.FindControl("lbl_Title"), Label)
'Access text of label using label1.text and cast to int or string
End If