Two Part GridView Question
-
ONE I have a ButtonField column in a GridView like so:
asp:ButtonField DataTextField="Day" HeaderText="Date" CommandName="Detail"
It lists the dates.. like 2,3,4,5,6 and so on in each GridRow. I want to fetch the date as an integer. I tried:
int nDay = Convert.ToInt32(gvStats.SelectedRow.Cells[0].Text);
but the SelectedRow is null. How do I go about it? ie:What object holds the correct value? TWO In my former DataGrid I have:
if (dgClicks.DataKeys[dgItem.DataSetIndex] != System.DBNull.Value)
can this be written as
if (gvClick.DataKeys[gvRow.DataSetIndex].Value != System.DBNull.Value)
Will it work correctly? Is this a valid conditional? ANY help on either would be GREATLY appreciated. Thanks Practice sesquipedalianism! ;)
-
ONE I have a ButtonField column in a GridView like so:
asp:ButtonField DataTextField="Day" HeaderText="Date" CommandName="Detail"
It lists the dates.. like 2,3,4,5,6 and so on in each GridRow. I want to fetch the date as an integer. I tried:
int nDay = Convert.ToInt32(gvStats.SelectedRow.Cells[0].Text);
but the SelectedRow is null. How do I go about it? ie:What object holds the correct value? TWO In my former DataGrid I have:
if (dgClicks.DataKeys[dgItem.DataSetIndex] != System.DBNull.Value)
can this be written as
if (gvClick.DataKeys[gvRow.DataSetIndex].Value != System.DBNull.Value)
Will it work correctly? Is this a valid conditional? ANY help on either would be GREATLY appreciated. Thanks Practice sesquipedalianism! ;)
Question 1: The
SelectedRow
property of the GridView control isnull
until you make aSelect
command, so you may replace the command name"Detail"
with the"Select"
. If you want to use "Detail" as the command name, you can simply convert the ButtonField into a TemplateField with a Button so that you can pass theDay
value in theCommandArgument
property. You may also keep using the ButtonField with the Day value passed along with theCommandName
. Question 2: TheGridViewRow
class does not have theDataSetIndex
property, but it has a similar one namedDataItemIndex
, so it can rewritten like this:if (gvClick.DataKeys[gvRow.DataItemIndex].Value != System.DBNull.Value)