我已经生成了一个按钮字段的事件,这样我就可以得到行的索引,但是我无法获得列的内容
请问你能帮帮我吗
我可以使用select查询,其中我传递行的索引(我不知道如何在where子句中写入条件)
Protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "affichediplome") {
int index = Convert.ToInt32(e.CommandArgument);
GridViewRow row = GridView1.Rows[index];
int ServerID = Convert.ToInt32(GridView1.DataKeys[index].Value); MessageBox.Show(index.ToString());
}
}
答案 0 :(得分:1)
试试这个..
添加一个绑定字段以存储您不想向用户显示的信息,但您必须在服务器端使用它。
<asp:datagrid GridLines="None" id="dg" AutoGenerateColumns="False" Runat="server" BorderStyle="None">
<Columns>
<asp:BoundColumn DataField="ID" visible="false"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="Sr. No." ItemStyle-Width="5%">
</asp:TemplateColumn>
</Columns>
<asp:BoundColumn DataField="ModuleName" HeaderText="Module Name">
</asp:BoundColumn>
</asp:datagrid>
然后在服务器端,您可以获得如下数据。
Private Sub dg_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles dgWebinarData.ItemDataBound
Dim str as string = string.empty
str = e.Item.Cells(1).Text
End sub
注意:当且仅当ID将是您的第一列网格时,e.Item.Cells(1)将为您提供ID,否则提供列号。