以下のようなコードでグリッド ビューの 2 列目からデータを取得したいのですが、何も返されません (di.Cells[1].Text) 。何が問題なのか教えてください。
protected void btnShowAddTransmittaltoCon_Click(object sender, EventArgs e)
{
Transmittallistfortest transmittalList = (Transmittallistfortest)DetailsView1.FindControl("Transmittallistfortest1");
GridView g3 = transmittalList.FindControl("GridViewTtransmittals") as GridView;
foreach (GridViewRow di in g3.Rows)
{
RadioButton rad = (RadioButton)di.FindControl("RadioButton1");
//Giving Error:Object reference not set to an instance of an object.
if (rad != null && rad.Checked)
{
var w = di.RowIndex;
Label1.Text = di.Cells[1].Text;
}
aspx は次のようになります。
<asp:GridView ID="GridViewTtransmittals" runat="server" AutoGenerateColumns="False"
BorderStyle="None" ShowHeader="False" Width="100%" DataKeyNames="TransID" onrowdatabound="GridViewTtransmittals_RowDataBound"
onrowdeleting="GridViewTtransmittals_RowDeleting">
<columns>
<asp:TemplateField>
<ItemTemplate>
<asp:RadioButton ID="RadioButton1" runat="server" GroupName="Transmittal" AutoPostBack="True"
OnCheckedChanged="RadioButton1_CheckedChanged" />
</ItemTemplate>
</asp:TemplateField>
<asp:hyperlinkfield DataNavigateUrlFields="TransId"
DataNavigateUrlFormatString="~/Copy of Transmittal.aspx?TransId={0}" DataTextField="TRANSMITTAL"
HeaderText="Transmittal" />
<asp:CommandField ButtonType="Button" ShowDeleteButton="true" />