Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/265.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何检查列中单元格的值是否正确=无效的_C#_Asp.net - Fatal编程技术网

C# 如何检查列中单元格的值是否正确=无效的

C# 如何检查列中单元格的值是否正确=无效的,c#,asp.net,C#,Asp.net,我正在尝试更新gridview,以检查某列中的单元格是否为!=NULL(检查用户是否向单元格中写入了内容) 我的问题是我不知道如何从单元格中获取“x列”值。我假设您通过以下方式接近 您有一个页脚模板,并且可能有一个保存页脚值的按钮 网格中的每一行都有一个编辑/更新按钮 方法1(即页脚模板) 你可以在下面找到类似的 TextBox testing = (TextBox)grd.FooterRow.FindControl("Your Control ID"); 方法2(即使用编辑/更新按钮)

我正在尝试更新gridview,以检查某列中的单元格是否为!=NULL(检查用户是否向单元格中写入了内容)


我的问题是我不知道如何从单元格中获取“x列”值。

我假设您通过以下方式接近

  • 您有一个页脚模板,并且可能有一个保存页脚值的按钮
  • 网格中的每一行都有一个编辑/更新按钮

  • 方法1(即页脚模板) 你可以在下面找到类似的

    TextBox testing = (TextBox)grd.FooterRow.FindControl("Your Control ID");
    

    方法2(即使用编辑/更新按钮) 你可以像下面这样做

    隐藏的示例代码

    protected void grd_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        TextBox testing = (TextBox)grd.Rows[e.RowIndex].FindControl("Your Control ID");
    }
    

    示例HTML

    <asp:GridView ID="grd" runat="server" onrowupdating="grd_RowUpdating">
    </asp:GridView>
    

    inzi irina请查看此代码。如果这对你有帮助,别忘了给我投票

    private void button2_Click(object sender, EventArgs e)
        {
            foreach (DataGridViewRow dr in dataGridView1.Rows)
            {
                string lngth = Convert.ToString(dr.Cells[1].Value);
                if (lngth.Length > 0)
                {
                    listBox1.Items.Add(dr.Cells[0].Value);
                }
            }
        }
    

    您使用的是什么数据库框架?Linq to SQL、实体框架、ADO.Net?它不起作用,我只想从行更新的单元格中获取值。您应该有一个grd_行更新事件处理程序。这将使你的生活变得非常简单。是的,但是,控制id=?列的id?模板集us中textbox控件的id