在以下示例中,我无法获取 tel 输入“Contract”的值。我对 DropDownList 没有任何问题。
asp 代码:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="Serial,Model" DataSourceID="ObjectDataSource1" Width="50%" GridLines="None" CellSpacing="-1">
<Columns>
<asp:BoundField DataField="Serial" HeaderText="Serial" />
<asp:BoundField DataField="Model" HeaderText="Model"/>
<asp:TemplateField HeaderText="Status">
<ItemTemplate>
<asp:DropDownList ID="Status" CssClass="dropdownlist" runat="server" onfocus="setSelectedRow(this)" DataValueField="Status" SelectedValue='<%# Bind("Status") %>' onChange="statusChange(this)">
<asp:ListItem Value="RENT READY">Rent Ready</asp:ListItem>
<asp:ListItem Value="ON RENT">On Rent</asp:ListItem>
<asp:ListItem Value="OOS">Out of Service</asp:ListItem>
</asp:DropDownList>
<input type="tel" id="Contract" onfocus="setSelectedRow(this)" value= '<%# Eval("Contract") %>' placeholder="Contract #" class='<%# (string)Eval("Status") == "ON RENT" ? "textBox" : "textBoxHidden" %>'></input>
</ItemTemplate>
</asp:TemplateField>
</asp:GridView>
呈现的 HTML:
到目前为止我已经尝试过:
protected void submit_Click(object sender, EventArgs e)
{
if (!Page.IsValid) return;
foreach(GridViewRow row in GridView1.Rows)
{
string Serial = row.Cells[0].Text;
string Model = row.Cells[1].Text;
string Status = ((DropDownList)row.FindControl("Status")).SelectedValue;
string Contract = Any one of the below attempts...
Sql stored procedure integrating the data back to the server...
}
}
string Contract = ((HtmlInputControl)row.FindControl("Contract")).Value;
string Contract = ((HtmlInputText)row.FindControl("Contract")).Value;
string Contract = ((TextBox)row.FindControl("Contract")).Text;
全部抛出 Object Reference Not Set to Instance of Object 异常。