我有一个使用EmptyDataTemplate的ASP.NET GridView。在EmptyDataTemplate内部,我有一些文本框和一个用于插入记录的提交按钮。当我尝试访问代码隐藏文件中的ID时,它们没有显示出来。
我的代码:
<asp:GridView ID="gv" runat="server" AutoGenerateColumns="False" BackColor="White"
BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1px" CellPadding="4" ForeColor="Black"
GridLines="Vertical">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:BoundField DataField="BankName" HeaderText="Bank Name" />
<asp:BoundField DataField="IFSCCode" HeaderText="IFSC Code" />
<asp:BoundField DataField="MICRCODE" HeaderText="MICR Code" />
<asp:BoundField DataField="BranchName" HeaderText="Branch Name" />
<asp:BoundField DataField="Address" HeaderText="Address" />
</Columns>
<EmptyDataTemplate>
<div style="border: 1px solid #ccc; width: auto; margin: 20px 470px;">
<table border="0" cellpadding="2" cellspacing="0">
<tr>
<th colspan="3" bgcolor="#1e7c9a" style="color: White">
Please Enter Your Bank Details
</th>
</tr>
<tr>
<td>
Bank Name
</td>
<td>
<asp:TextBox ID="txtBankname" runat="server" Width="180px" />
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" ErrorMessage="Required"
ForeColor="Red" ControlToValidate="txtBankname" runat="server" Width="120" />
</td>
</tr>
<tr>
<td>
IFSC Code
</td>
<td>
<asp:TextBox ID="txtIfsccode" runat="server" Width="180px" />
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" ErrorMessage="Required"
ForeColor="Red" ControlToValidate="txtIfsccode" runat="server" />
</td>
</tr>
<tr>
<td>
MICR Code
</td>
<td>
<asp:TextBox ID="txtMicrcode" runat="server" Width="180px" />
</td>
<td>
</td>
</tr>
<tr>
<td>
Branch Name
</td>
<td>
<asp:TextBox ID="txtBranchName" runat="server" Width="180px" />
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" ErrorMessage="Required"
Display="Dynamic" ForeColor="Red" ControlToValidate="txtBranchName" runat="server" />
</td>
</tr>
<tr>
<td>
Address
</td>
<td>
<asp:TextBox ID="txtAddress" runat="server" TextMode="MultiLine" />
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" ErrorMessage="Required"
ForeColor="Red" ControlToValidate="txtAddress" runat="server" />
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:Button ID="btn" Text="Submit" runat="server" OnClick="InsertDetails"/>
</td>
<td>
</td>
</tr>
</table>
</div>
</EmptyDataTemplate>
<FooterStyle BackColor="#CCCC99" />
<HeaderStyle BackColor="#1e7c9a" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />
<RowStyle BackColor="#F7F7DE" />
<SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#FBFBF2" />
<SortedAscendingHeaderStyle BackColor="#848384" />
<SortedDescendingCellStyle BackColor="#EAEAD3" />
<SortedDescendingHeaderStyle BackColor="#575357" />
</asp:GridView>
答案 0 :(得分:1)
试试这个
Button Insert_Details = gv.Controls[0].Controls[0].FindControl("btn") as Button ;
您可以看到 EXAMPLE
答案 1 :(得分:0)
OP解决方案。
完成如下:
$sql = "INSERT INTO `user_sessions`(`email`, `ip_address`, `location`, `lat`, `lng`, `device_type`, `device_imei`, `login_date`, `login_time`, `active`) VALUES (?,?,?,?,?,?,?,?,?,?);";
$stmt2 = mysqli_stmt_init($con);
if(!mysqli_stmt_prepare($stmt2, $sql)){
$data['result'] = "SQL error";
echo json_encode($data);
exit();
} else {
mysqli_stmt_bind_param($stmt2, "sssddsssss", $email, $ip, $city, $lat, $lng, $user_device, $user_device_imei, $user_date, $user_time, "1");
mysqli_stmt_execute($stmt2);
$data['result'] = "login success";
$data['user_id'] = $row['user_id'];
echo json_encode($data);
exit();
}