c# - C#通过单击单元格获取GridView的行索引
问题描述
我有这个 GridView:
<asp:GridView ID="gvTabelaTeste" runat="server" AutoGenerateColumns="false" CssClass="w3-table w3-striped w3-white w3-hoverable w3-centered" OnRowDataBound="gvTabelaTeste_RowDataBound">
<Columns>
<asp:BoundField DataField="Status" HeaderText="Status"/>
<asp:BoundField DataField="Atividade" HeaderText="Atividade"/>
<asp:BoundField DataField="Analista" HeaderText="Analista"/>
<asp:BoundField DataField="DtInicial" HeaderText="Data de abertura"/>
<asp:BoundField DataField="DtFinal" HeaderText="Data de validade"/>
</Columns>
</asp:GridView>
这两个div:
<div id="light" class="white_content">
<h6 style="background-color: lightgray; margin-bottom: 0; margin-top: 0; text-align: center;"><strong>Escolher nova data de validade</strong></h6>
<asp:Calendar ID="Calendario" runat="server" OnSelectionChanged="Calendario_SelectionChanged"></asp:Calendar>
</div>
<div id="fade" class="black_overlay"></div>
我将此代码放在 GridView 中的 RowDataBound 事件上:
e.Row.Cells[4].Attributes["onclick"] = "document.getElementById('light').style.display='block';document.getElementById('fade').style.display='block';";
因此,当我单击每行的单元格 4 时,它会更改 div 的样式显示,使其类似于弹出窗口。在 div 我有一个日历,其中包含有关 SelectionChanged 事件的代码:
gvTabelaTeste.Rows[/*here should be the row index*/].Cells[4].Text = Calendario.SelectedDate.ToShortDateString();
我要做的是将单击的单元格的文本更改为日历上的选定日期,但问题是我无法获取单击的单元格行的索引。
我怎样才能做到这一点?我尝试了不同的方法,但直到现在没有人为我工作。
解决方案
如何获取 rowIndex 已在此处得到解答:WPF- How to get selected row index in datagrid?
看看这是否符合您的需求。
推荐阅读
- elasticsearch - Elasticsearch - 是否有一个选项或标志来防止使用查询搜索索引
- r - 如何从具有特定索引的选定行中计算平均值
- java - 如何将自定义类型的 ArrayList 传递给 AsyncTask 的 doInBackground?
- vue.js - 如果任何字段为空,则该按钮应禁用
- excel - 删除使用excel从公式计算的空白单元格
- python - 如何用 imshow 图替换 x 轴上的缩放比例?
- go - 有没有办法在 io.multiwriter 中附加时间戳?
- reactjs - 从 Promise 调用操作时未定义然后阻塞
- hibernate - 如何以编程方式设置休眠时区?
- javascript - 为什么使用本地依赖时没有触发 onClick 处理程序?