gridview 相关问题

Gridview是用于显示和操作来自各种数据源的数据的控件。

如何在gridview中启用和禁用超链接?

我在模板字段中有一个超链接。我想根据其值启用和禁用超链接。假设如果 Id 是“ABC”,我想禁用超链接。我尝试了下面的代码,但没有......

回答 1 投票 0

HiddenField.ValueChanged 从 Javascript 更改时不会触发事件

更新 我将 Javascript 移至 ASPX 站点,并为其添加了回发功能。现在可以了。感谢@orgtigger,特别是@lucidgold 花时间帮助我! 她...

回答 3 投票 0

如何摆脱包含GridView的空div

在 ASP.NET Gridviews 中生成一个表,该表生成一个父 div 容器。这可能会破坏 CSS 布局,因为无法将样式附加到生成的 div。有没有办法防止div

回答 2 投票 0

网格/列表视图的概念如何将图像发送到imageitem类

在我的项目中,我想加载 url 图像并在 gridview 活动中显示它们。但如何将这些图像加载到 gridview 适配器呢? 所以我试图理解网格/列表视图适应的概念...

回答 1 投票 0

GridView 中的 ASP VB.Net 复选框无法正常工作,出现错误 BC30311 类型“Control”的值无法转换为 CheckBox

我已在工作网格视图中添加了一个复选框,如下所示。 我已在工作网格视图中添加了一个复选框,如下所示。 <asp:Panel ID="Reasons" runat="server"> <ContentTemplate> <div class="container"> <p style="font-weight:800; font-size: 14px; color: #593196;">Open Dissatisfiers - Select Open Dissatisfiers to Add Resolution(s)</p> <asp:GridView ID="GridReasons" runat="server" AutoGenerateColumns="False" Width="100%" CssClass="table table-bordered border-primary table-hover table-sm" AllowPaging="True" DataKeyNames="InteractionID,KeyID" PageSize="10" Font-Size="Smaller" EnableViewState="False"> <Columns> <asp:TemplateField> <ItemTemplate> <asp:CheckBox ID="SelectCheckBox" runat="server" AutoPostBack="true"/> </ItemTemplate> </asp:TemplateField> <asp:BoundField DataField="KeyID" HeaderText="Key ID" SortExpression="KeyID" DataFormatString="{0}" ItemStyle-Width="70"/> <asp:BoundField DataField="Type_Desc" HeaderText="Dissatisfier" SortExpression="Dissatisfier Type" ItemStyle-Width="300" /> <asp:BoundField DataField="Reason_Desc" HeaderText="Reason" SortExpression="Reason_Desc" ItemStyle-Width="300" /> <asp:BoundField DataField="Interaction_Reason_Desc" HeaderText="Dissatisifer Details" SortExpression="Interaction_Reason_Desc" ItemStyle-Width="900"/> </Columns> <EmptyDataTemplate> <div> No Open Dissatisfiers/Reasons</div> </EmptyDataTemplate> </asp:GridView> </div> </ContentTemplate> </asp:Panel> 当它运行代码来浏览网格视图并对任何检查到的内容采取操作时,它会失败。 Protected Function GetSelectedRows() As Integer Dim intCount As Integer = 0 Dim intRow As Integer = 0 For Each row As GridViewRow In GridReasons.Rows intRow = intRow + 1 Dim chk As CheckBox = TryCast(row.Cells(0).FindControl("SelectCheckBox"), CheckBox) If chk Is Nothing Then ' Code if nothing found Else If chk.Checked Then intCount = intCount + 1 'Code if checked Else ' Code if not checked End If End If Next GetSelectedRows = intCount End Function 此行导致错误 Dim chk As CheckBox = TryCast(row.Cells(0).FindControl("SelectCheckBox"), CheckBox) 我尝试了很多变体,但结果相同。 我已经用 AutoPostBack 尝试过 true 和 false。我正在使用 Visual Studio 2022 如果有帮助的话。 一般来说,任何模板化列都不需要,也不使用 cells() 集合。 因此这应该有效: Dim chk As CheckBox = FindControl("SelectCheckBox") 根据您的项目设置,您可能需要将演员重新引入复选框。

回答 1 投票 0

如何为SqlDataSource UpdateCommand设置参数

对于网格视图: 我第一次尝试在 SQLDataSource 中为 UpdateCommand 使用存储过程: 对于网格视图: 我第一次尝试在 SQLDataSource 中为 UpdateCommand 使用存储过程: <asp:SqlDataSource ID="TECT_DataSource" runat="server" ConnectionString="<%$ ConnectionStrings:OracleConnectionString %>" ProviderName="<%$ ConnectionStrings:OracleConnectionString.ProviderName %>" SelectCommand="SELECT MPID, User_Id, Last_Name, First_Name FROM Scripts.vw_Tect_Exam" UpdateCommand="P_TECT_UPD_EXAM_ID" UpdateCommandType="StoredProcedure"> <UpdateParameters> <asp:Parameter Name="MPID" Type="Int32" /> <asp:Parameter Name="User_Id" Type="String" /> </UpdateParameters> </asp:SqlDataSource> 我想知道 UpdateParameters 如何设置它们的值,因为我只指定了一个名称? 过程 P_TECT_UPD_EXAM_ID 需要两个参数作为输入:"in_MPID" 和 "in_UserId" 我还想知道如何将这些值映射到过程的输入参数,因为名称不同? 你可以这样设置它们: 示例:示例中 MPID 是 sql 参数名称@MPID <UpdateParameters> <asp:ControlParameter Name="MPID" ControlID="MPID_TextBox" PropertyName="Text" /> <asp:ControlParameter Name="User_Id" ControlID="User_Id_TextBox" PropertyName="Text" /> </UpdateParameters> 更正:刚刚发现你的过程参数名称,所以它一定是 <asp:ControlParameter Name="in_MPID" ............... <asp:ControlParameter Name="in_User_Id" ............... 我真的不会使用SqlDataSource。如果您在代码隐藏中(或者更好的是在数据访问层中)调用数据库,则会容易得多。 如果您使用 SqlDataSource,则存储过程调用将仅在该页面上可用。每次您想要拨打相同的电话时,您都必须复制并粘贴 SqlDataSource 或从中创建 UserControl。 以下示例使用实体框架连接到数据库并检索记录: public List<Record> GetAllRecordsByUserName(string credentials) { List<Record> recordList; using (CustomEntities context = new CustomEntities()) { IQueryable<Section> recordQuery = from records in context.Records where records.UserName == credentials select records; recordList = recordQuery.ToList<Record>(); } return recordList; }

回答 2 投票 0

在 gridview 中,每行都有 2 个下拉菜单。选择第一个下拉列表中的值后,它应该在第二个下拉列表中显示下拉值

下拉菜单依赖于另一个下拉菜单。 这是我尝试过的 ASPX gridview 中的下拉菜单依赖于另一个下拉菜单。 here is what i tried aspx 选择程序 </asp:DropDownList> <asp:RequiredFieldValidator ID="rfvddlProgram" runat="server" ErrorMessage="*" ControlToValidate="ddlProgram" Font-Bold="False" Font-Names="Verdana" Font-Size="8pt" SetFocusOnError="True" ValidationGroup="v1" ForeColor="Red" InitialValue="0"></asp:RequiredFieldValidator> <%-- <a href="#" target="_blank">BA Economics</a>--%> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Location"> <ItemTemplate> <asp:DropDownList ID="ddl_Location" runat="server" class="form-control form-control-sm mb-9"> <asp:ListItem Value="0">Select Location</asp:ListItem> </asp:DropDownList> <asp:RequiredFieldValidator ID="rfvddlLocation" runat="server" ErrorMessage="*" ControlToValidate="ddl_Location" Font-Bold="False" Font-Names="Verdana" Font-Size="8pt" SetFocusOnError="True" ValidationGroup="v1" ForeColor="Red" InitialValue="0"></asp:RequiredFieldValidator> </ItemTemplate> </asp:TemplateField> </Columns> <FooterStyle BackColor="White" ForeColor="#000066" /> <HeaderStyle BackColor="#6777ef" Font-Bold="True" ForeColor="White" /> <PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" /> <RowStyle ForeColor="#000066" /> <SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" /> <SortedAscendingCellStyle BackColor="#F1F1F1" /> <SortedAscendingHeaderStyle BackColor="#007DBB" /> <SortedDescendingCellStyle BackColor="#CAC9C9" /> <SortedDescendingHeaderStyle BackColor="#00547E" /> code behind file protected void gvProgram_RowDataBound(object sender, GridViewRowEventArgs e) { DataSet ds = new DataSet(); Btech.Mode = "BindData"; ds = objDal.Adm(Btech); if (e.Row.RowType == DataControlRowType.DataRow) { if (ds.Tables[0].Rows.Count > 0 && ds.Tables[1].Rows.Count > 0) { DropDownList ddlProgram = (DropDownList)e.Row.FindControl("ddlProgram"); ddlProgram.Items.Clear(); ddlProgram.DataSource = ds.Tables[13]; ddlProgram.DataTextField = "Description"; ddlProgram.DataValueField = "CourseID"; ddlProgram.DataBind(); ddlProgram.Items.Insert(0, new ListItem("Select course", "0")); DropDownList ddl_Location = (DropDownList)e.Row.FindControl("ddl_Location"); //ddlTeacherNames.Items.Clear(); ddl_Location.DataSource = ds.Tables[14]; ddl_Location.DataTextField = "CenterName"; ddl_Location.DataValueField = "CentreCode"; ddl_Location.DataBind(); ddl_Location.Items.Insert(0, new ListItem("Select Location", "0")); } } } protected void ddlProgram_SelectedIndexChanged(对象发送者,EventArgs e) { } 好吧,有几件事我们必须处理。 首先,加载 GridView。 然后我们必须加载 2 个组合框,但还要为 2 个组合框设置正确的级联值。然后我们必须根据行数据源设置组合框的正确值。所以,理论上这里有 3 个步骤。这一步有点倒退,因为第二个组合框选择和值必须在第一个组合框中设置正确的值。 然后,完成上述所有操作后,我们需要将组合框设置为在用户选择第一个组合框时正确级联,并级联到该 GridRow 中的第二个组合框。 通常,这表明第一个组合框未绑定到给定行中的任何数据,但只有第二个组合框要绑定到给定行数据。 我没有你的样本数据,但让我们假设一些人,我们选择城市,然后第二个级联组合框是他们选择的酒店。 所以,首先是我们的 GridView 标记: <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="ID" CssClass="table" Width="30%" OnRowDataBound="GridView1_RowDataBound"> <Columns> <asp:BoundField DataField="Firstname" HeaderText="Firstname" /> <asp:BoundField DataField="LastName" HeaderText="LastName" /> <asp:TemplateField HeaderText="Select Hotel City"> <ItemTemplate> <asp:DropDownList ID="cboCity" runat="server" Width="120px" Height="26px" DataTextField = "City" DataValueField = "City" AutoPostback="true" OnSelectedIndexChanged="cboCity_SelectedIndexChanged" > </asp:DropDownList> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Select Hotel"> <ItemTemplate> <asp:DropDownList ID="cboHotels" runat="server" Width="210px" Height="26px" DataValueField ="ID" DataTextField ="HotelName"> </asp:DropDownList> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> 我还要指出,我不关心 GridView 事件,我建议您也不要打扰。 所以,首先是加载组合框的代码。 DataTable rstCity = new DataTable(); protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) LoadGrid(); } void LoadGrid () { // load up City list for combo box - all rows (scope = page) SqlCommand cmdSQL = new SqlCommand("SELECT City from City ORDER BY City"); rstCity = MyRstP(cmdSQL); // load up the grid cmdSQL.CommandText = "SELECT * from People ORDER BY FirstName"; GridView1.DataSource = MyRstP(cmdSQL); GridView1.DataBind(); } 好的,上面加载了 GridView。 但是,如上所述,虽然我们有 2 个组合框(选择城市,然后在给定城市列表中选择一家酒店),但只需要保存第二个组合框选择。 因此,在行数据绑定中,我们不仅要加载2个组合框,还要正确设置城市选择,然后根据该酒店加载酒店,然后选择酒店。 protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { DataRowView gData = (DataRowView)e.Row.DataItem; // get the row data // load the city combo box DropDownList cboCity = (DropDownList)e.Row.FindControl("cboCity"); cboCity.DataSource = rstCity; cboCity.DataBind(); // add blank row for city cboCity.Items.Insert(0, new ListItem("Select City", "")); // We have to check if a hotel been selected. SqlCommand cmdSQL = new SqlCommand(); DropDownList cboHotels = (DropDownList)e.Row.FindControl("cboHotels"); Debug.Print($"<{gData["Hotel_ID"].ToString()}>"); if (gData["Hotel_ID"] != DBNull.Value) { cmdSQL = new SqlCommand("SELECT ID, City, HotelName FROM tblHotels WHERE ID = @ID"); cmdSQL.Parameters.Add("@ID", SqlDbType.Int).Value = gData["Hotel_ID"]; DataRow OneHotel = MyRstP(cmdSQL).Rows[0]; // now load Hotel combo box - but cascade from above City cbo string strSQL = @"Select ID, HotelName From tblHotels WHERE City = @City " + " ORDER BY HotelName"; cmdSQL = new SqlCommand(strSQL); cmdSQL.Parameters.Add("@City", SqlDbType.NVarChar).Value = OneHotel["City"]; DataTable rstHotels = MyRstP(cmdSQL); cboHotels.DataSource = rstHotels; cboHotels.DataBind(); cboHotels.Items.Insert(0, new ListItem("Select Hotel", "")); // set hotels combo to current selected cboHotels.SelectedValue = gData["Hotel_id"].ToString(); // set City combo box to current selected City cboCity.SelectedValue = OneHotel["City"].ToString(); } } } 所以,上面设置了一切。 接下来是城市选择的级联。因此,请注意上面的组合框的标记是这样的: <asp:TemplateField HeaderText="Select Hotel City"> <ItemTemplate> <asp:DropDownList ID="cboCity" runat="server" Width="120px" Height="26px" DataTextField = "City" DataValueField = "City" AutoPostback="true" OnSelectedIndexChanged="cboCity_SelectedIndexChanged" > </asp:DropDownList> </ItemTemplate> 注意 autopost back = true 的情况。并记下组合框的事件设置。 所以,城市组合框更改事件是这样的: protected void cboCity_SelectedIndexChanged(object sender, EventArgs e) { // city changed, so cascade Hotel cbo DropDownList cboCity = (DropDownList)sender; GridViewRow gRow = (GridViewRow)cboCity.NamingContainer; // filter hotels to current city string strCity = cboCity.SelectedItem.Text; DropDownList cboHotels = (DropDownList)gRow.FindControl("cboHotels"); if (strCity != "Select City") { SqlCommand cmdSQL = new SqlCommand(@"SELECT * from tblHotels WHERE City = @City ORDER BY HotelName"); cmdSQL.Parameters.Add("@City", SqlDbType.NVarChar).Value = strCity; cboHotels.DataSource = MyRstP(cmdSQL); cboHotels.DataBind(); cboHotels.Items.Insert(0, new ListItem("Select Hotel", "")); } } 当然,用户进行更改后,我们需要保存更改。所以,我们的保存按钮是这样的: protected void cmdSave_Click(object sender, EventArgs e) { foreach(GridViewRow gRow in GridView1.Rows) { DropDownList cboHotel = (DropDownList)gRow.FindControl("cboHotels"); if (cboHotel.SelectedIndex > 0) rstGrid.Rows[gRow.RowIndex]["Hotel_id"] = cboHotel.SelectedItem.Value; } using (SqlConnection conn = new SqlConnection(Properties.Settings.Default.TEST4)) { string strSQL = "SELECT * FROM People ORDER BY FirstName,ID"; using (SqlCommand cmdSQL = new SqlCommand(strSQL, conn)) { conn.Open(); SqlDataAdapter da = new SqlDataAdapter(cmdSQL); SqlCommandBuilder dau = new SqlCommandBuilder(da); da.Update(rstGrid); } } } 结果是这样的: 所以,结果看起来像这样:

回答 1 投票 0

带有标题的Flutter GridView

如何在 FLUTTER 中创建带有可滚动工具栏的网格视图。我找到了带有标题 ListViewWithHeader 的列表视图。但我需要带有标题的 GridView,如下图所示。我有

回答 2 投票 0

yii2 在 gridview 中更改控制器操作

我有 ItemController 并在 actionView 中放置了 Itempicture 的 gridview,我希望当我单击图标视图时,更新和删除,然后转到 ItempictureController。 那么如何更改控制器活动...

回答 5 投票 0

Flutter:在 GridView 平铺中使用 GestureDetector 进行点击延迟

通常,以下行为本质上是快速的。然而,在 GridView (或我假设的任何 ScrollView (也尝试过 ListView))内,性能似乎非常差。当我点击屏幕时,...

回答 1 投票 0

如何在WPF MVVM中显示带有动态列的表格

我有一个对象列表,每个对象都包含用户定义的属性。这些属性的键和值是自由字符串,因此它们在对象之间不一定一致。无论如何,我

回答 1 投票 0

gridview点击后如何知道点击了哪个单元格

我有一个 PROJECT_EFFORT 表。 项目 ID、年份、月份、工作量 1, 2022, 12, 10 2, 2022, 12, 20 2, 2023, 1, 100 2, 2023, 2, 50 2, 2023, 3, 30 3, 2023, 3, 40 3, 2023, 4, 10 3, 2023, 5, 120 4、...

回答 1 投票 0

在GridView中显示当地时间

我有一个asp.net gridview绑定到以下sql server 2008r2数据源: 我有一个asp.net gridview绑定到以下sql server 2008r2数据源: <asp:SqlDataSource ID="dsFault" runat="server" DataSourceMode="DataSet" ConnectionString="<%$ ConnectionStrings:ESBExceptionDb %>" SelectCommand="select * from Fault order by datetime desc"></asp:SqlDataSource> 在我的故障表中有一个名为 DateTime 的列,其类型为日期时间。此列中存储的值采用 UTC 格式,我需要将它们显示在浏览器的本地时区 我已将模板字段添加到网格视图的列集合中,如下所示: <asp:TemplateField> <ItemTemplate> <asp:Label ID="lblLocalTime" runat="server" Text='<%# String.Format("{0:f}", Eval("DateTime").ToLocalTime()) %>'> </asp:Label> </ItemTemplate> </asp:TemplateField> 当我浏览页面时,出现以下错误: CS1061: 'object' does not contain a definition for 'ToLocalTime' and no extension method 'ToLocalTime' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?) 谁能告诉我哪里出了问题? 谢谢,罗布。 从数据库返回的 Eval("DateTime") Value 不是 C# DataTime 对象。 并且因为函数 .ToLocalTime() 属于 DateTime c# 对象,所以你不能使用它。 您需要将对象转换为字符串,然后使用函数.ToLocalTime() <asp:TemplateField> <ItemTemplate> <asp:Label ID="lblLocalTime" runat="server" Text='<%# Convert.ToDateTime(Eval("DateTime")).ToLocalTime() %>'> </asp:Label> </ItemTemplate> </asp:TemplateField> 将其转换为 DateTime 对象,您可以使用任何可用的格式 例如 Text='<%# Convert.ToDateTime(Eval("DateTime")).ToString("dd/MM/yyyy") %>' 除了其他答案之外,请记住 ToLocalTime() 将返回服务器本地时间,而不是您请求的浏览器本地时间。 尝试这样 <%# Eval("DateTime", "{0:T}")%> <asp:Label ID="lblLocalTime" runat="server" Text='<%# Eval("DateTime", "{0:T}")%>'> </asp:Label> 这样就可以了!尝试一下。 <asp:TemplateField HeaderText="Account Created"> <ItemTemplate> <asp:Label ID="lblLocalTime" runat="server" Text='<%# Convert.ToDateTime(Eval("CreateDate", "{0:g}")).ToLocalTime() %>'> </asp:Label> </ItemTemplate> </asp:TemplateField> 看起来没有干净简单的方法可以做到这一点,奇怪!到目前为止提到的答案尝试将日期转换为服务器时区,而不是客户端/浏览器的时区。即,如果服务器位于美国而客户端位于印度,您将看不到印度时区的日期时间,它将是美国时区的日期时间。 其中的重复有更好的答案。基本上,您必须执行以下操作之一 - 将客户端时区信息发送到服务器并在那里进行适当的转换。最好发送时区名称而不是时区偏移量,因为时区偏移量可能因 DST 而异。您可以使用 Intl.DateTimeFormat().resolvedOptions().timeZone 发送时区名称。 将 UTC 日期字符串发送至 客户端并让它使用 javascript 进行转换(新 日期(ISOUTCDateString))。这就是 WCF 中发生的情况。 谢谢你。它工作完美。它对我很有帮助。

回答 6 投票 0

ASP.NET GridView RowCommand 文本框为空

嗨,我有一个网格视图,每行都有一个文本框,我试图获取 RowCommand 事件中的值。下面的代码适用于除第一行之外的所有行。 ... 的 textbox.text 值

回答 2 投票 0

visual studio 2010 asp.net gridview 不是已知元素

我使用的是带有SP1的VS2010 Pro。由于某种原因,它抱怨我所有的 Gridview 控件,仅此而已。我没有看到标记中有任何错误。 到目前为止我已经尝试了两件事 遵循

回答 2 投票 0

Android:动态添加单元格到GridView?

我想在用户到达最后一行单元格时动态地将单元格添加到GridView,就像显示更多一样?

回答 2 投票 0

从 GridView 解码 TextBox.Text

我有一个GridView控件。每行都有一个文本框,其中包含我需要的描述。当我拉回描述时,我看到 (") 已被编码: TextBox selectedRowTextbox = (TextBox)selecte...

回答 1 投票 0

ASP.NET:有关 gridviews 中的列行换行功能的问题

我有一个带有几列的 ASP.NET gridview(嵌入在 DIV 中)。对于某些列,定义了换行,而对于某些列则没有定义换行(使用 ItemStyle.Wrap = true/false)。对于所有列 ItemStyle.Width 是 s...

回答 2 投票 0

我们有一个虚拟数据,我们使用该数据来创建一个使用该类别的颜色、id 或标题的网格视图。我不明白的视频部分如下

我们有一个虚拟数据,我们使用该数据来创建一个使用该类别的颜色、id 或标题的网格视图。 。我无法确切理解此代码片段的目的是什么。你可以吗

回答 1 投票 0

还有另一种有效的方法将数据更新到gridview内的数据库吗?

所以我在这里所做的是将gridview内的数据插入和更新到数据库的过程。我在更新时遇到了一些问题。当我将数据插入多个...

回答 1 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.