I'm creating this thread as a followed up from my previous one here.
I'm trying to create a gridview filled some data from my database. However, as you can see from the bottom 3 boundfield, i have prevented them from appearing on my webapp.
<Columns>
<asp:BoundField DataField="memberreportid" HeaderText="property" SortExpression="false"/>
<asp:BoundField DataField="typeofcrime" HeaderText="property" SortExpression="false" />
<asp:BoundField DataField="crdatetime" HeaderText="property" SortExpression="false" />
<asp:BoundField DataField="address" HeaderText="property" SortExpression="false" />
<asp:BoundField DataField="detail" HeaderText="property" SortExpression="false"/>
<asp:BoundField DataField="incidentdate" HeaderText="property" SortExpression="false" />
<asp:BoundField DataField="incidenttime" HeaderText="victim" SortExpression="false"/>
<asp:BoundField DataField="property" HeaderText="suspect" SortExpression="false" Visible="false" />
<asp:BoundField DataField="victim" HeaderText="suspect" SortExpression="false" Visible="false" />
<asp:BoundField DataField="suspect" HeaderText="suspect" SortExpression="false" Visible="false" />
</Columns>
I'm trying to display them out onto the label despite them not being able to see physically via the webpage. I used this method to display them out when the select button is being clicked ( I have set "AutoGenerateSelectColumn" to true)
protected void GWCase_SelectedIndexChanged(object sender, EventArgs e)
{
lbmemberreportid.Text = GWCase.SelectedRow.Cells[1].Text;
lblproperty.Text = GWCase.SelectedRow.Cells[8].Text;
lblvictim.Text = GWCase.SelectedRow.Cells[9].Text;
lblsuspect.Text = GWCase.SelectedRow.Cells[10].Text;
}
Unfortunately, i'm only able to display out the memberreportID onto the label but not the other 3 attirbute which i believe it doesn't because i hid it physically. Is there any other method apart from the one i attempted to display out the specific value when being selected in the gridview?
UPDATED
Page_load binding
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
LoadGrid();
}
}
private void LoadGrid()
{
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Data Source = localhost; Initial Catalog = MajorProject; Integrated Security= SSPI";
conn.Open();
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter("SELECT memberreportid, typeofcrime, crdatetime, address, detail, incidentdate, incidenttime, property, victim, suspect, detail, suspectdetail, propertydetail from memberreport", conn);
da.Fill(ds);
GWCase.DataSource = ds.Copy();
GWCase.DataBind();
conn.Close();
ddlpid1.Visible = false;
ddlpid2.Visible = false;
ddlpid3.Visible = false;
ddlpid4.Visible = false;
ddlpid5.Visible = false;
ddlpid6.Visible = false;
ddlpid7.Visible = false;
ddlpid8.Visible = false;
ddlpid9.Visible = false;
ddlpid10.Visible = false;
}
Trying to read the hidden field
protected void GWCase_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
LoadGrid();
GWCase.PageIndex = e.NewPageIndex;
GWCase.DataBind();
}