Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.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# 如何在ASP.NET中使用DropDownList删除GridView中的一行_C#_Asp.net - Fatal编程技术网

C# 如何在ASP.NET中使用DropDownList删除GridView中的一行

C# 如何在ASP.NET中使用DropDownList删除GridView中的一行,c#,asp.net,C#,Asp.net,这是我的设计页面 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="newsamplecomb._Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitiona

这是我的设计页面

 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs"     Inherits="newsamplecomb._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
 <asp:GridView ID="GridView1" runat="server" ShowFooter="true"   AutoGenerateColumns="False"
        BackColor="#DEBA84" BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px"
        CellPadding="3" CellSpacing="2"    OnSelectedIndexChanged="GridView1_SelectedIndexChanged1"
        Height="246px" onrowdatabound="GridView1_RowDataBound" Width="1017px">
        <RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" />
        <Columns>
            <asp:BoundField />
            <asp:TemplateField>
                <HeaderTemplate>
                    Rollno<br />
                </HeaderTemplate>
                <ItemTemplate>
                    <asp:DropDownList ID="DropDownList1" runat="server" Height="23px"    Width="73px" 
                        AutoPostBack="True" 
                        onselectedindexchanged="DropDownList1_SelectedIndexChanged" >
                    </asp:DropDownList>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField>
                <HeaderTemplate>
                    Name
                </HeaderTemplate>
                <ItemTemplate>
                    <asp:TextBox ID="TextBox1" runat="server" Width="155px"    ReadOnly="True"></asp:TextBox>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField>
                <HeaderTemplate>
                    English<br />
                </HeaderTemplate>
                <ItemTemplate>
                    <asp:TextBox ID="TextBox2" runat="server" Height="17px" Width="103px"></asp:TextBox>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField>
                <HeaderTemplate>
                    Tamil<br />
                </HeaderTemplate>
                <ItemTemplate>
                    <asp:TextBox ID="TextBox3" runat="server" Height="16px" Width="103px"></asp:TextBox>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField>
                <HeaderTemplate>
                    Maths
                </HeaderTemplate>
                <ItemTemplate>
                    <asp:TextBox ID="TextBox4" runat="server" Height="16px" Width="103px"></asp:TextBox>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField>
                <HeaderTemplate>
                    Science
                </HeaderTemplate>
                <ItemTemplate>
                    <asp:TextBox ID="TextBox5" runat="server" Height="16px" Width="103px"></asp:TextBox>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField>
                <HeaderTemplate>
                    Total<br />
                </HeaderTemplate>
                <ItemTemplate>
                    <asp:TextBox ID="TextBox6" runat="server" Height="16px" Width="103px"></asp:TextBox>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField>
                <HeaderTemplate>
                    Grade
                </HeaderTemplate>
                <ItemTemplate>
                    <asp:TextBox ID="TextBox7" runat="server" Height="16px" Width="103px"></asp:TextBox>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField>
                <ItemTemplate>
                    <asp:Button ID="ButtonAdd" runat="server" OnClick="ButtonAdd_Click1" Text="+" />
                    <asp:Button ID="Buttondel" runat="server" Text="Del"></asp:Button>
                   <asp:RequiredFieldValidator ID="rfv" runat="server" ErrorMessage="" ForeColor="White" ControlToValidate="TextBox1" Width="10" Display="None"></asp:RequiredFieldValidator>
                </ItemTemplate>
                <FooterStyle HorizontalAlign="Right" />
            </asp:TemplateField>
        </Columns>
        <FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />
        <PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" />
        <SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" />
        <HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White" />
    </asp:GridView>

</div>
<%-- //<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"        ErrorMessage="RequiredFieldValidator" ForeColor="White" ControlToValidate="TextBox1" Width="10"></asp:RequiredFieldValidator>--%>

罗尔诺
名称 英语
泰米尔语
数学 科学类 总计
等级

这是我的cs代码

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            var ddl = (DropDownList)e.Row.FindControl("DropDownList1");
            string connection_string = ConfigurationManager.ConnectionStrings["DBC"].ConnectionString;
            SqlConnection con = new SqlConnection(connection_string);
            con.Open();

            SqlCommand cmd = new SqlCommand("Select * from stud_table", con);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();

            da.Fill(ds);
            //  con.Close();
            ddl.DataSource = ds;
            ddl.DataTextField = "Rollno";
            ddl.DataValueField = "Rollno";
            ddl.DataBind();
            ddl.Items.Insert(0, new ListItem("--Select--", "0"));
        }
    }

    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        dpditemdesc( sender,e);
        DropDownList box1 = (DropDownList)GridView1.Rows[x].Cells[1].FindControl("DropDownList1");

        if (box1.Text != "")
        {
            for (int i = 0; i < GridView1.Rows.Count; i++)
            {
                GridView1.Rows[i].Cells[2].Enabled = false;
                GridView1.Rows[i].Cells[3].Enabled = false;
                GridView1.Rows[i].Cells[4].Enabled = false;
                GridView1.Rows[i].Cells[5].Enabled = false;
                GridView1.Rows[i].Cells[6].Enabled = false;
                GridView1.Rows[i].Cells[7].Enabled = false;
                GridView1.Rows[i].Cells[8].Enabled = false;
            }
        }
        else
        {
            for (int i = 0; i < GridView1.Rows.Count; i++)
            {
                GridView1.Rows[i].Cells[2].Enabled = true;
                GridView1.Rows[i].Cells[3].Enabled = true;
                GridView1.Rows[i].Cells[4].Enabled = true;
                GridView1.Rows[i].Cells[5].Enabled = true;
                GridView1.Rows[i].Cells[6].Enabled = true;
                GridView1.Rows[i].Cells[7].Enabled = true;
                GridView1.Rows[i].Cells[8].Enabled = true;
            }
        }
    }
    public void dpditemdesc(object sender, EventArgs e)
    {
        DropDownList ddl = (DropDownList)sender;
        GridViewRow row = (GridViewRow)ddl.NamingContainer;
        x = row.RowIndex;
        TextBox box = (TextBox)GridView1.Rows[x].Cells[2].FindControl("TextBox1");
        if (box.Text == "")
        {
            try
            {
                x = Convert.ToInt32(Session["ct"].ToString());
                x++;
                Session["ct"] = x.ToString();
            }
            catch
            {
                x = 0;
                Session["ct"] = x.ToString();
            }
        }
        if (ddl.SelectedIndex != 0)
        {
        string connection_string =     ConfigurationManager.ConnectionStrings["DBC"].ConnectionString;
        SqlConnection con = new SqlConnection(connection_string);

        DropDownList box1 =                                 (DropDownList)GridView1.Rows[x].Cells[1].FindControl("DropDownList1");
        TextBox box2 = (TextBox)GridView1.Rows[x].Cells[2].FindControl("TextBox1");
        TextBox box3 = (TextBox)GridView1.Rows[x].Cells[3].FindControl("TextBox2");
        TextBox box4 = (TextBox)GridView1.Rows[x].Cells[4].FindControl("TextBox3");
        TextBox box5 = (TextBox)GridView1.Rows[x].Cells[5].FindControl("TextBox4");
        TextBox box6 = (TextBox)GridView1.Rows[x].Cells[6].FindControl("TextBox5");
        TextBox box7 = (TextBox)GridView1.Rows[x].Cells[7].FindControl("TextBox6");
        TextBox box8 = (TextBox)GridView1.Rows[x].Cells[8].FindControl("TextBox7");


        SqlCommand cmd = new SqlCommand("select * from stud_table where Rollno='" + box1.Text + "'", con);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            da.Fill(ds);
            box2.Text = ds.Tables[0].Rows[0][1].ToString();
            box3.Text = ds.Tables[0].Rows[0][2].ToString();
            box4.Text = ds.Tables[0].Rows[0][3].ToString();
            box5.Text = ds.Tables[0].Rows[0][4].ToString();
            box6.Text = ds.Tables[0].Rows[0][5].ToString();
            box7.Text = ds.Tables[0].Rows[0][6].ToString();
            box8.Text = ds.Tables[0].Rows[0][7].ToString();
        }
        else
        {
            // box.Text = "";
            Response.Write("<Script>alert('Please Select Item Description')</script>");
        }

    }
}
}
受保护的无效GridView1\u行数据绑定(对象发送方,GridViewRowEventArgs e)
{
如果(e.Row.RowType==DataControlRowType.DataRow)
{
var ddl=(DropDownList)e.Row.FindControl(“DropDownList1”);
字符串连接\u string=ConfigurationManager.ConnectionString[“DBC”].ConnectionString;
SqlConnection con=新的SqlConnection(连接\u字符串);
con.Open();
SqlCommand cmd=新的SqlCommand(“从螺柱表格中选择*”,con);
SqlDataAdapter da=新的SqlDataAdapter(cmd);
数据集ds=新数据集();
da.填充(ds);
//con.Close();
ddl.DataSource=ds;
ddl.DataTextField=“Rollno”;
ddl.DataValueField=“Rollno”;
ddl.DataBind();
Insert(0,newlistItem(“--Select--”,“0”);
}
}
受保护的void DropDownList1\u SelectedIndexChanged(对象发送方,事件参数e)
{
dpdtemdesc(发送方,e);
DropDownList box1=(DropDownList)GridView1.Rows[x]。Cells[1]。FindControl(“DropDownList1”);
如果(box1.Text!=“”)
{
对于(int i=0;i