我有一个GridView
,我用它来逐行将信息传递给另一个页面。但是当我使一个列不可见时,它会传递0作为值。这是我的GridView
,与TaskId
有问题。
<asp:GridView ID="GridView1" runat="server"
Width="936px" AllowPaging="True" AutoGenerateColumns="False"
CellPadding="3" DataSourceID="SqlDataSource1"
OnRowCommand="GridView1_RowCommand" style="text-align: center"
BackColor="#DEBA84" BorderColor="#DEBA84" BorderStyle="None"
BorderWidth="1px" CellSpacing="2"
OnSelectedIndexChanged="GridView1_SelectedIndexChanged"
AllowSorting="True">
<Columns>
<asp:BoundField DataField="TaskId" HeaderText="TaskId" Visible="false"
ReadOnly="True" SortExpression="TaskId" />
<asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
<asp:BoundField DataField="Body" HeaderText="Body"
SortExpression="Body" Visible="false" />
<asp:BoundField DataField="Reward" HeaderText="Reward(Rs)"
SortExpression="Reward" />
<asp:BoundField DataField="TimeAllotted" HeaderText="Time(Min)"
SortExpression="TimeAllotted" />
<asp:BoundField DataField="PosterName" HeaderText="Uploader"
SortExpression="PosterName" />
<asp:ButtonField ButtonType="Button" CommandName="Select"
Text="Perform Task" ControlStyle-ForeColor="White"
ControlStyle-Font-Bold="true">
<ControlStyle BackColor="#CC6600" Font-Bold="True"
ForeColor="White"/>
</asp:ButtonField>
</Columns>
答案 0 :(得分:3)
您需要使用GridView
的{{3}}属性。
如果要访问其值,请在其中指定不可见的列名:
<asp:GridView ID="GridView1" runat="server" DataKeyNames="TaskId" .../>
您可以访问以下值:
foreach (GridViewRow row in GridView1.Rows)
{
int TASKID = Convert.ToInt32(GridView1.DataKeys[row.RowIndex].Values[0]);
}