0

という名前の列を持つ GridView があり、Run TimeTextBoxes を使用していますrTime。私は、この GridView を android オペレーティング システムで実行し、誰かがテキスト ボックスをクリックするとキーパッドが表示されるようにしたいと考えています。これは GridView なしで以前は機能していましたが、The name 'rTime' does not exist in the current contextエラーが発生しています。これが私のaspxコードです: `

   <asp:TemplateField HeaderText="labelID" Visible="false">
        <ItemTemplate>
            <asp:Label ID="ID" runat="server" Text='<%# Eval("Id") %>' />
        </ItemTemplate>
    </asp:TemplateField>

    <asp:TemplateField HeaderText="First Name">
        <ItemTemplate>
            <asp:Label ID="labelfirstname" Visible="true" runat="server" Text='<%# Eval("fName") %>' />

        </ItemTemplate>
    </asp:TemplateField>
     <asp:TemplateField HeaderText="Last Name">
        <ItemTemplate>
            <asp:Label ID="labellastname" Visible="true" runat="server" Text='<%# Eval("lName") %>' />
        </ItemTemplate>
    </asp:TemplateField>
     <asp:TemplateField HeaderText="Run Time Needed">
        <ItemTemplate>
            <asp:Label ID="labelrTimeN" Visible="true" runat="server" Text='<%# Eval("rTimeN") %>' />
        </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Run Time">
        <ItemTemplate>
            <div style="display:none"><asp:TextBox ID="rTime" runat="server" Height="16px" 
        ontextchanged="TextBox1_TextChanged" Width="108px"></asp:TextBox></div>
    <span class="style4"><strong>Meter Run:</strong></span><span class="style5">&nbsp;</span><input onblur="document.getElementById('<%=rTime.ClientID %>').value = this.value" 
    type="tel" style="width: 100px; height: 31px;" />
        </ItemTemplate>
    </asp:TemplateField>


</Columns>
</asp:GridView>`

ここにC#があります:

private bool isEditMode = false;
    protected void Page_Load(object sender, EventArgs e)
    {

        if (!Page.IsPostBack)
        {
            BindData();
        }
        UpdatePanel1.Visible = false;
    }
    private void BindData()
    {

        string connectiongString = "Data Source=WSCJTCSQ1;Initial Catalog=TestDB;Persist Security Info=True;User ID=v2soft;Password=passwordv2soft";
        SqlConnection myConnection = new SqlConnection(connectiongString);
        SqlDataAdapter ad = new SqlDataAdapter("SELECT Id, fName, lName, rTimeN, rTime FROM bleaTest", myConnection);
        DataSet ds = new DataSet();
        ad.Fill(ds);
        GridView1.DataSource = ds;
        GridView1.DataBind();

    }



    protected void Button1_Click(object sender, EventArgs e)
    {
        isEditMode = true;
        UpdatePanel1.Visible = true;
        BindData();
    }
    protected void TextBox1_TextChanged(object sender, EventArgs e)
    {

    }

    protected void Button2_Click(object sender, EventArgs e)
    {
        Update();
    }
    protected bool IsInEditMode
    {

        get { return this.isEditMode; }

        set { this.isEditMode = value; }

    }


    private void Update()
    {
        StringBuilder sb = new StringBuilder();

        foreach (GridViewRow row in GridView1.Rows)
        {
            sb.Append("UPDATE bleaTest SET rTime = '");

            sb.Append((row.FindControl("rTime") as TextBox).Text);

            sb.Append("'");

            sb.Append(" WHERE id = ");

            sb.Append(Convert.ToInt32((row.FindControl("ID") as Label).Text));

            sb.Append(" ");

        }
        string connectiongString = "Data Source=WSCJTCSQ1;Initial Catalog=TestDB;Persist Security Info=True;User ID=v2soft;Password=passwordv2soft";
        SqlConnection myConnection = new SqlConnection(connectiongString);
        SqlCommand myCommand = new SqlCommand(sb.ToString(), myConnection);
        myConnection.Open();
        myCommand.ExecuteNonQuery();
        myConnection.Close();

        isEditMode = false;

        BindData();

        UpdatePanel1.Visible = false;

    }
    protected void gvUsers_RowDataBound(object sender, GridViewCommandEventArgs e)
    {

    }

前もって感謝します!!

4

1 に答える 1

0

さらに調査を行い、コードを少し書き直しました。アップデートは次のとおりです。

<asp:TemplateField HeaderText="Run Time">
        <ItemTemplate>
           <div style="display:none"> <asp:TextBox ID="rTime" runat="server" type="number" Text='<%# Eval("rTime") %>' ></asp:TextBox></div>
           <input onblur="document.getElementById('<%# ((GridViewRow)Container).FindControl("rTime").ClientID %>').value = this.value" 
    type="tel" style="width: 100px; height: 31px;" />
        </ItemTemplate>
于 2012-11-08T16:26:23.160 に答える