temprarygridviews with radio,fileupload,droupdoun using asp.net with C#

insert data into form

insert data into form


design.aspx



<%@ Page Language="C#" AutoEventWireup="true" CodeFile="fileradiodroupexample.aspx.cs" Inherits="fileradiodroupexample" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<!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 bgcolor="#3399CC">
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>

    <div>
        <center><table border="1"  bordercolor="black">
            <tr>
                <td>
                    <asp:Label ID="Label6" ForeColor="White" runat="server" Text="company id"></asp:Label>
                </td>
                <td>
                    <asp:TextBox ID="TextBox6" runat="server"></asp:TextBox>
                </td>
                <td>
                    <asp:CompareValidator ID="CompareValidator1" runat="server"
          ErrorMessage="only digit is allowed" ControlToValidate="TextBox6" Display="Dynamic"
          Font-Bold="True" Type="Integer" Operator="DataTypeCheck"></asp:CompareValidator>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="Please enter id"
                    ControlToValidate="TextBox6" SetFocusOnError="true" Display="Dynamic"></asp:RequiredFieldValidator>
                   
                </td>
            </tr>
            <tr>
                <td>
                    <asp:Label ID="Label1" ForeColor="White" runat="server" Text="company name"></asp:Label>
                </td>
                <td>
                    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                </td>
                <td>
                    <asp:RequiredFieldValidator ID="rfvFirstName"

                 runat="server"

                 ControlToValidate="TextBox1"

                ErrorMessage="company Name can't be left blank"

                Display="Dynamic"> </asp:RequiredFieldValidator>
                </td>
            </tr>
            <tr>
                <td>
                    <asp:Label ID="Label7" runat="server" ForeColor="White" Text="enter image"></asp:Label>
                </td>
                <td>
                    <asp:FileUpload ID="FileUpload1" runat="server" />
                </td>
                <td>
                    <asp:RequiredFieldValidator ID="fileup"

                 runat="server"

                 ControlToValidate="FileUpload1"

                ErrorMessage="image can't be left blank"

                Display="Dynamic"> </asp:RequiredFieldValidator>
                </td>
            </tr>
            <tr>
                <td>
                    <asp:Label ID="Label2" ForeColor="White" runat="server" Text="persion name"></asp:Label>
                </td>
                <td>
                    <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
                </td>
                <td>
                    <asp:RequiredFieldValidator

             ID="RequiredFieldValidator2" runat="server"

             ControlToValidate="TextBox2"

             ErrorMessage="person name can't be left blank"

             Display="Dynamic"> </asp:RequiredFieldValidator>
                </td>
            </tr>
            <tr>
                <td>
                    <asp:Label ID="Label10" runat="server" ForeColor="White" Text="gender"></asp:Label>
                </td>
                <td>
                    <asp:RadioButtonList ForeColor="White" ID="RadioButtonList1" runat="server">
                    <asp:ListItem Text=male Value="0" ></asp:ListItem>
                    <asp:ListItem Text="female" Value="1"></asp:ListItem>
                    </asp:RadioButtonList>
                </td>
                <td>
                    <asp:RequiredFieldValidator

             ID="gender" runat="server"

             ControlToValidate="RadioButtonList1"

             ErrorMessage="gender can't be left blank"

             Display="Dynamic"> </asp:RequiredFieldValidator>
                </td>
            </tr>
            <tr>
                <td>
                    <asp:Label ID="Label8" ForeColor="White" runat="server" Text="enter state"></asp:Label>
                </td>
                <td>
                    <asp:UpdatePanel ID="up1" runat="server">
                    <ContentTemplate>
                   
                    <asp:DropDownList ID="DropDownList1" runat="server"
                        onselectedindexchanged="DropDownList1_SelectedIndexChanged1" DataTextField="statename" DataValueField="statename" AutoPostBack="true">
                    </asp:DropDownList>
                    </ContentTemplate>
                    </asp:UpdatePanel>
                </td>
                <td>
                    <asp:RequiredFieldValidator

             ID="state" runat="server"

             ControlToValidate="DropDownList1"

             ErrorMessage="state name can't be left blank"

             Display="Dynamic"> </asp:RequiredFieldValidator>
                </td>
            </tr>
            <tr>
                <td>
                    <asp:Label ID="Label9"  ForeColor="White" runat="server" Text="enter City"></asp:Label>
                </td>
                <td>
                    <asp:UpdatePanel ID="up2" runat="server">
                        <ContentTemplate>
                    <asp:DropDownList ID="DropDownList2" AutoPostBack="true" runat="server" DataTextField="city" DataValueField="city">
                    </asp:DropDownList>
                    </ContentTemplate>
                    </asp:UpdatePanel>
                </td>
                <td>
                    <asp:RequiredFieldValidator

             ID="city" runat="server"

             ControlToValidate="DropDownList2"

             ErrorMessage="city name can't be left blank"

             Display="Dynamic"> </asp:RequiredFieldValidator>
                </td>
            </tr>
            <tr>
                <td >
                    <asp:Label ID="Label3" ForeColor="White" runat="server" Text="company phone"></asp:Label>
                </td>
                <td >
                    <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
                </td>
                <td>
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator4"

             runat="server"

           

             ControlToValidate="TextBox3"

        

             ErrorMessage="phoneno can't be left blank"

             SetFocusOnError="True" Display="Dynamic"></asp:RequiredFieldValidator>

        <asp:RegularExpressionValidator ID="RegularExpressionValidator3" runat="server"
            ErrorMessage="only number is allowed and 6 digit number" ControlToValidate="TextBox3"
            Display="Dynamic" ValidationExpression="^[0-9]{6}"></asp:RegularExpressionValidator>
                </td>

            </tr>
            <tr>
                <td>
                    <asp:Label ID="Label4" ForeColor="White" runat="server" Text="company mobile"></asp:Label>
                </td>
                <td>
                    <asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
                </td>
                <td>
               
                <asp:RequiredFieldValidator ID="RequiredFieldValidator5"

             runat="server"

           

             ControlToValidate="TextBox4"

        

             ErrorMessage="cellno can't be left blank"

             SetFocusOnError="True" Display="Dynamic"></asp:RequiredFieldValidator>

        <asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server"
            ErrorMessage="only number is allowed" ControlToValidate="TextBox4"
            Display="Dynamic" ValidationExpression="^[0-9]{10}"></asp:RegularExpressionValidator>
                </td>
            </tr>
            <tr>
                <td>
                    <asp:Label ID="Label5" ForeColor="White" runat="server" Text="company address"></asp:Label>
                </td>
                <td>
                    <asp:TextBox ID="TextBox5" runat="server"></asp:TextBox>
                </td>
                <td>
                         <asp:RequiredFieldValidator

             ID="RequiredFieldValidator3" runat="server"

             ControlToValidate="TextBox5"

             ErrorMessage="Address can't be left blank"

             Display="Dynamic"> </asp:RequiredFieldValidator>
              
                </td>
            </tr>
            <tr>
                <td>
                    <asp:Button ID="Button4" runat="server" Text="update" onclick="Button4_Click" 
                        Visible="false" CausesValidation="False"/></td>
                <td>
                    <asp:Button ID="Button1"  runat="server" Text="add" onclick="Button1_Click" />
                    <asp:Button ID="Button3" runat="server" Text="clear" onclick="Button3_Click"
                        CausesValidation="False" />
                </td>
               
            </tr>
        </table>
                    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
                DataKeyNames="com_id">
                <Columns>
                       <asp:TemplateField HeaderText="ID">
                            <ItemTemplate>
                                <asp:Label ID="Label8" runat="server" Text='<%#Eval("com_id") %>'></asp:Label>
                            </ItemTemplate>
                       </asp:TemplateField>
                       <asp:TemplateField HeaderText="c_nm">
                            <ItemTemplate>
                                <asp:Label ID="Label7" runat="server" Text='<%#Eval("com_name") %>'></asp:Label>
                            </ItemTemplate>
                           
                       </asp:TemplateField>
                       <asp:TemplateField HeaderText="image">
                                <ItemTemplate>
                                    <asp:Image ID="Image1" runat="server"  Width="80" Height="80" ImageUrl='<%#Eval("image") %>' />
                                    <asp:Label ID="Label16" runat="server" Text='<%#Eval("image") %>' Visible="false"></asp:Label>
                                </ItemTemplate>
                       </asp:TemplateField>
                       <asp:TemplateField HeaderText="p_nm">
                            <ItemTemplate>
                                <asp:Label ID="Label9" runat="server" Text='<%#Eval("per_name") %>'></asp:Label>
                            </ItemTemplate>
                       </asp:TemplateField>
                       <asp:TemplateField HeaderText="gender">
                                <ItemTemplate>
                                    <asp:Label ID="Label13" runat="server" Text='<%#Eval("gender") %>'></asp:Label>
                                </ItemTemplate>
                               
                       </asp:TemplateField>
                       <asp:TemplateField HeaderText="state">
                            <ItemTemplate>
                                <asp:Label ID="Label14" runat="server" Text='<%#Eval("state") %>'></asp:Label>
                            </ItemTemplate>
                       </asp:TemplateField>
                       <asp:TemplateField HeaderText="city">
                                <ItemTemplate>
                                    <asp:Label ID="Label15" runat="server" Text='<%#Eval("city") %>'></asp:Label>
                                </ItemTemplate>
                       </asp:TemplateField>
                       <asp:TemplateField HeaderText="ph_no">
                            <ItemTemplate>
                                <asp:Label ID="Label10" runat="server" Text='<%#Eval("com_ph") %>'></asp:Label>
                            </ItemTemplate>
                       </asp:TemplateField>
                       <asp:TemplateField HeaderText="mo_no">
                            <ItemTemplate>
                                <asp:Label ID="Label11" runat="server" Text='<%#Eval("com_mo") %>'></asp:Label>
                            </ItemTemplate>
                       </asp:TemplateField>
                       <asp:TemplateField HeaderText="c_add">
                            <ItemTemplate>
                                <asp:Label ID="Label12" runat="server" Text='<%#Eval("com_add") %>'></asp:Label>
                            </ItemTemplate>
                       </asp:TemplateField>
                       <asp:TemplateField HeaderText="edit">
                            <ItemTemplate>
                                                                                               <asp:LinkButton ID="LinkButton1" OnClick="edit" runat="server" CausesValidation="False">edit</asp:LinkButton>
                            </ItemTemplate>
                       </asp:TemplateField>
                       <asp:TemplateField HeaderText="delete">
                            <ItemTemplate>
                                <asp:LinkButton ID="LinkButton2" runat="server" OnClick="delete"  CommandArgument='<%#Eval("com_id") %>' CausesValidation="False">Delete</asp:LinkButton>
                            </ItemTemplate>
                           
                       </asp:TemplateField>
                </Columns>
            </asp:GridView>
            <asp:Button ID="Button2" runat="server" Text="submit"
                onclick="Button2_Click1" CausesValidation="False" />

    </div>
   
   
    </form>
</body>
</html>


design.aspx.cs



using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.IO;

public partial class fileradiodroupexample : System.Web.UI.Page
{
    DataTable dt;
    DataTable dt1;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Page.IsPostBack)
        {
            dt = Session["data_table"] as DataTable;

        }
        if (!Page.IsPostBack)
        {
            Session["data_table"] = null;
            Bind_ddlstate();

        }
        if (Request.QueryString["c_id"] != null)
        {
            string con = @"Data Source=SQLDB;Initial Catalog=Demo;User ID=Demoh;Password=Demo1@";
            SqlConnection conn = new SqlConnection(con);
            string q = "select c.com_id,c.com_name,c.image,c.per_name,c.gender,s.statename as 'state' ,cc.city,c.com_ph,c.com_mo,c.com_add from pi_comp1 c INNER JOIN pi_statedemo s ON c.state=s.id INNER JOIN pi_citydemo cc ON c.city=cc.cid where com_id='" + Request.QueryString["c_id"].ToString() + "'";

            SqlDataAdapter da = new SqlDataAdapter();
            DataTable ds = new DataTable();
            SqlCommand cmd1 = new SqlCommand(q, conn);
            conn.Open();
            da.SelectCommand = cmd1;

            cmd1.ExecuteNonQuery();
            da.Fill(ds);
            GridView1.DataSource = ds;
            GridView1.DataBind();
            dt = ds;
            conn.Close();

        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
      
            FileUpload1.SaveAs(Server.MapPath("~/image/") + FileUpload1.FileName);
       
        if (dt == null)
        {
            dt = new DataTable();
            DataColumn dc0 = new DataColumn("com_id");
            DataColumn dc1 = new DataColumn("com_name");
            DataColumn dc2 = new DataColumn("image");
            DataColumn dc3 = new DataColumn("per_name");
            DataColumn dc4 = new DataColumn("gender");
            DataColumn dc5 = new DataColumn("state");
            DataColumn dc6 = new DataColumn("city");
            DataColumn dc7 = new DataColumn("com_ph");
            DataColumn dc8 = new DataColumn("com_mo");
            DataColumn dc9 = new DataColumn("com_add");
            //dt.Columns.Add(dc0);
            dt.Columns.Add(dc0);
            dt.Columns.Add(dc1);
            dt.Columns.Add(dc2);
            dt.Columns.Add(dc3);
            dt.Columns.Add(dc4);
            dt.Columns.Add(dc5);
            dt.Columns.Add(dc6);
            dt.Columns.Add(dc7);
            dt.Columns.Add(dc8);
            dt.Columns.Add(dc9);
        }


        DataRow dr1 = dt.NewRow();
        dr1[0] = TextBox6.Text;
        dr1[1] = TextBox1.Text;
        dr1[2] = "~/image/"+FileUpload1.FileName;
        dr1[3] = TextBox2.Text;
        if (RadioButtonList1.SelectedIndex == 0)
        {
            string m = "male";
            dr1[4] = m.ToString();
        }
        else
        {
            string f = "female";
            dr1[4] = f.ToString();
        }
        dr1[5] = DropDownList1.SelectedValue;
        dr1[6] = DropDownList2.SelectedValue;
        dr1[7] = TextBox3.Text;
        dr1[8] = TextBox4.Text;
        dr1[9] = TextBox5.Text;
        dt.Rows.Add(dr1);
        GridView1.DataSource = dt;
        GridView1.DataBind();
        Session["data_table"] = dt;
        TextBox6.Text = "";
        TextBox1.Text = "";
        TextBox2.Text = "";
        TextBox3.Text = "";
        TextBox4.Text = "";
        TextBox5.Text = "";
        DropDownList1.SelectedIndex = -1;
        DropDownList2.SelectedIndex = -1;
    }
    protected void edit(object sender, EventArgs e)
    {

       LinkButton lt = (LinkButton)sender;
       GridViewRow rw = (GridViewRow)lt.NamingContainer;
        Label cid = rw.FindControl("Label8") as Label;
        TextBox6.Text = cid.Text;
        Label cnm = rw.FindControl("Label7") as Label;
        TextBox1.Text = cnm.Text;
        Label pnm = rw.FindControl("Label9") as Label;
        TextBox2.Text = pnm.Text;
        Label pno = rw.FindControl("Label10") as Label;
        TextBox3.Text = pno.Text;
        Label mno = rw.FindControl("Label11") as Label;
        TextBox4.Text = mno.Text;
        Label cadd = rw.FindControl("Label12") as Label;
        TextBox5.Text = cadd.Text;
        TextBox6.ReadOnly = true;

        Label st = rw.FindControl("Label14") as Label;
        DropDownList1.SelectedValue = st.Text;
        Label ct = rw.FindControl("Label15") as Label;
        DropDownList2.Items.Insert(0, (ct.Text));

        Button1.Visible = false;
        Button4.Visible = true;
    }
    protected void delete(object sender, EventArgs e)
    {
        //Session["id"]
        string idb= ((LinkButton)sender).CommandArgument;
        LinkButton st = (LinkButton)sender;
        GridViewRow rw = (GridViewRow)st.NamingContainer;
        Label id = (Label)rw.FindControl("Label18");
        foreach (GridViewRow r in GridView1.Rows)
        {
           string sid = GridView1.DataKeys[r.RowIndex].Values[0].ToString();
          
           
           
            //if (sid.Equals(Session["id"]))
           if (sid.Equals(idb))
            {
                dt.Rows.RemoveAt(r.RowIndex);
               
            }
        }
        GridView1.DataSource = dt;
                GridView1.DataBind();
    }
  





    public void Bind_ddlstate()
    {

        string con = @"Data Source=SQLDB;Initial Catalog=Demo;User ID=Demoh;Password=Demo1@";
        SqlConnection conn = new SqlConnection(con);
        conn.Open();
        string q = "select * from pi_statedemo";
        DataSet ds = new DataSet();
        SqlDataAdapter da = new SqlDataAdapter(q, conn);

        da.Fill(ds);

        DropDownList1.DataSource = ds;
        DropDownList1.DataBind();
        DropDownList1.Items.Insert(0, new ListItem("--select--"));
        conn.Close();


    }
    public void Bind_ddlCity()
    {
        DropDownList2.Items.Clear();
        string con = @"Data Source=SQLDB;Initial Catalog=Demo;User ID=Demoh;Password=Demo1@";
        SqlConnection conn = new SqlConnection(con);
        conn.Open();
        string q = "select city from pi_citydemo where id ='" + DropDownList1.SelectedIndex + "'";
        DataSet ds = new DataSet();
        SqlDataAdapter da = new SqlDataAdapter(q, conn);
        da.Fill(ds);
        DropDownList2.DataSource = ds;
        DropDownList2.DataBind();
        conn.Close();


    }
    protected void DropDownList1_SelectedIndexChanged1(object sender, EventArgs e)
    {
        Bind_ddlCity();
    }
    protected void Button2_Click1(object sender, EventArgs e)
    {
        string q;
        int i = 0;
        for (int r = 0; r < dt.Rows.Count; r++)
        {
            string j = null;
            if (dt.Rows[r][4] == "male")
            {
                 j = "0";
            }
            else
            {
                 j = "1";
            }

            string st = dt.Rows[r][5].ToString();
            string ct = dt.Rows[r][6].ToString();
            //Button btn = (Button)sender;
            //GridViewRow rw = (GridViewRow)btn.NamingContainer;
            //Label ct1 = (Label)rw.FindControl("Label15");
            string con = @"Data Source=SQLDB;Initial Catalog=Demo;User ID=Demoh;Password=Demo1@";
            SqlConnection conn = new SqlConnection(con);

            SqlDataAdapter adp = new SqlDataAdapter("select cid from pi_citydemo where city='" + ct + "'", conn);
            DataTable dt1 = new DataTable();
            adp.Fill(dt1);
           
            q = "insert into pi_comp1(com_id,com_name,image,per_name,gender,state,city,com_ph,com_mo,com_add) values ('" + dt.Rows[r][0].ToString() + "','" + dt.Rows[r][1].ToString() + "','" + dt.Rows[r][2].ToString() + "','" + dt.Rows[r][3].ToString() + "','" + j.ToString() + "','" + DropDownList1.Items.IndexOf(new ListItem(st)).ToString() + "','" + dt1.Rows[0]["cid"].ToString() + "','" + dt.Rows[r][7].ToString() + "','" + dt.Rows[r][8].ToString() + "','" + dt.Rows[r][9].ToString() + "')"; //+ g1.Cells[5].Text +
            SqlCommand cmd = new SqlCommand(q, conn);
            conn.Open();
            i = cmd.ExecuteNonQuery();
            conn.Close();
        }
        if (i > 0)
        {
            Response.Redirect("~/showfileradiodroup.aspx");
        }


    }
    protected void Button4_Click(object sender, EventArgs e)
    {
        if (Request.QueryString["c_id"] == null)
        {
            string sid = null;
            string t = TextBox6.Text;
            foreach (GridViewRow r in GridView1.Rows)
            {
                sid = GridView1.DataKeys[r.RowIndex].Values[0].ToString();
                Label l2 = (Label)GridView1.Rows[r.RowIndex].FindControl("Label16");
                Label id = (Label)GridView1.Rows[r.RowIndex].FindControl("Label18");
                if (sid.Equals(t))
                {
               
                    dt.Rows[r.RowIndex][0] = TextBox6.Text;
                    dt.Rows[r.RowIndex][1] = TextBox1.Text;
                    if (FileUpload1.HasFile)
                    {
                        FileUpload1.SaveAs(Server.MapPath("~/image/") + FileUpload1.FileName);
                        dt.Rows[r.RowIndex][2] = "~/image/" + FileUpload1.FileName;
                    }
                    else
                    {
                        dt.Rows[r.RowIndex][2] = l2.Text;
                    }
                    dt.Rows[r.RowIndex][3] = TextBox2.Text;
                    if (RadioButtonList1.SelectedIndex == 0)
                    {
                        string m = "male";
                        dt.Rows[r.RowIndex][4] = m.ToString();
                    }
                    else
                    {
                        string f = "female";
                        dt.Rows[r.RowIndex][4] = f.ToString();
                    }
                    dt.Rows[r.RowIndex][5] = DropDownList1.SelectedValue;
                    dt.Rows[r.RowIndex][6] = DropDownList2.SelectedValue;
                    dt.Rows[r.RowIndex][7] = TextBox3.Text;
                    dt.Rows[r.RowIndex][8] = TextBox4.Text;
                    dt.Rows[r.RowIndex][9] = TextBox5.Text;
                    TextBox6.ReadOnly = true;
                    GridView1.DataSource = dt;
                    GridView1.DataBind();
                    TextBox6.Text = "";
                    TextBox1.Text = "";
                    TextBox2.Text = "";
                    TextBox3.Text = "";
                    TextBox4.Text = "";
                    TextBox5.Text = "";
                    DropDownList1.SelectedIndex = -1;
                    DropDownList2.SelectedIndex = -1;
                    RadioButtonList1.SelectedIndex = -1;
                }
               
            }
        }
        else
        {
            string s = null;
                    string con = @"Data Source=SQLDB;Initial Catalog=Demo;User ID=Demoh;Password=Demo1@";
                    SqlConnection conn = new SqlConnection(con);
                    if (FileUpload1.HasFile)
                    {
                        FileUpload1.SaveAs(Server.MapPath("~/image/") + FileUpload1.FileName);
                         s = "~/image/" + FileUpload1.FileName;
                    }
                    else
                    {
                        foreach (GridViewRow r in GridView1.Rows)
                        {
                              
                            Label l2 = (Label)GridView1.Rows[r.RowIndex].FindControl("Label16");
                            s = l2.Text;
                        }
                    }
                    string gender = null;

                               

                    if (RadioButtonList1.SelectedIndex == 0 )
                    {
                        gender = "0";
                    }
                    else if (RadioButtonList1.SelectedIndex == 1)
                    {
                        gender = "1";
                    }
                    else
                    {
                        foreach (GridViewRow r in GridView1.Rows)
                        {

                            Label l13 = (Label)GridView1.Rows[r.RowIndex].FindControl("Label13");
                            gender = l13.Text;

                        }
                    }                
                     
                    
                    string q = "update  pi_comp1 set com_name='" + TextBox1.Text + "',image='" +  s + "',per_name='" + TextBox2.Text + "',gender='" + gender + "',state='" + DropDownList1.SelectedIndex.ToString() + "',city='" + DropDownList2.SelectedIndex.ToString() + "',com_ph='" + TextBox3.Text + "',com_mo='" + TextBox4.Text + "',com_add='" + TextBox5.Text + "' where com_id='" + TextBox6.Text + "'";
                    SqlCommand cmd = new SqlCommand(q, conn);
                    conn.Open();
                    int i = cmd.ExecuteNonQuery();
                    conn.Close();

                    if (i > 0)
                    {
                        Response.Redirect("~/showfileradiodroup.aspx");
                    }
        }
       

        Button4.Visible = false;
        Button1.Visible = true;
    }
    protected void Button3_Click(object sender, EventArgs e)
    {
        TextBox1.Text = "";
        TextBox2.Text = "";
        TextBox3.Text = "";
        TextBox4.Text = "";
        TextBox5.Text = "";
        TextBox6.Text = "";
       
       DropDownList1.SelectedIndex = -1;
       DropDownList2.SelectedIndex = -1;
       
       
    }
   
}

Show all detail of person

Click On edit Link
Now click on edit link

showDetail.aspx



<%@ Page Language="C#" AutoEventWireup="true" CodeFile="showfileradiodroup.aspx.cs" Inherits="showfileradiodroup" %>

<!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" AutoGenerateColumns="False"
            onrowdeleting="GridView1_RowDeleting" onrowediting="GridView1_RowEditing"
                >
                <Columns>
                       <asp:TemplateField HeaderText="ID">
                            <ItemTemplate>
                                <asp:Label ID="Label8" runat="server" Text='<%#Eval("com_id") %>'></asp:Label>
                            </ItemTemplate>
                       </asp:TemplateField>
                       <asp:TemplateField HeaderText="c_nm">
                            <ItemTemplate>
                                <asp:Label ID="Label7" runat="server" Text='<%#Eval("com_name") %>'></asp:Label>
                            </ItemTemplate>
                       </asp:TemplateField>
                       <asp:TemplateField HeaderText="image">
                                <ItemTemplate>
                                    <asp:Image ID="Image1" runat="server"  Width="80" Height="80" ImageUrl='<%#Eval("image") %>' />
                                </ItemTemplate>
                       </asp:TemplateField>
                       <asp:TemplateField HeaderText="p_nm">
                            <ItemTemplate>
                                <asp:Label ID="Label9" runat="server" Text='<%#Eval("per_name") %>'></asp:Label>
                            </ItemTemplate>
                       </asp:TemplateField>
                       <asp:TemplateField HeaderText="gender">
                                <ItemTemplate>
                                    <asp:Label ID="Label13" runat="server" Text='<%#Eval("gender") %>'></asp:Label>
                                </ItemTemplate>
                               
                       </asp:TemplateField>
                       <asp:TemplateField HeaderText="state">
                            <ItemTemplate>
                                <asp:Label ID="Label14" runat="server" Text='<%#Eval("statename") %>'></asp:Label>
                            </ItemTemplate>
                       </asp:TemplateField>
                       <asp:TemplateField HeaderText="city">
                                <ItemTemplate>
                                    <asp:Label ID="Label15" runat="server" Text='<%#Eval("city") %>'></asp:Label>
                                </ItemTemplate>
                       </asp:TemplateField>
                       <asp:TemplateField HeaderText="ph_no">
                            <ItemTemplate>
                                <asp:Label ID="Label10" runat="server" Text='<%#Eval("com_ph") %>'></asp:Label>
                            </ItemTemplate>
                           
                       </asp:TemplateField>
                       <asp:TemplateField HeaderText="mo_no">
                            <ItemTemplate>
                                <asp:Label ID="Label11" runat="server" Text='<%#Eval("com_mo") %>'></asp:Label>
                            </ItemTemplate>
                       </asp:TemplateField>
                       <asp:TemplateField HeaderText="c_add">
                            <ItemTemplate>
                                <asp:Label ID="Label12" runat="server" Text='<%#Eval("com_add") %>'></asp:Label>
                            </ItemTemplate>
                       </asp:TemplateField>
                       <asp:TemplateField HeaderText="edit">
                            <ItemTemplate>
                                <asp:LinkButton ID="LinkButton1" runat="server" CommandName="Edit">edit</asp:LinkButton>
                            </ItemTemplate>
                       </asp:TemplateField>
                       <asp:TemplateField HeaderText="delete">
                            <ItemTemplate>
                                                                <asp:LinkButton ID="LinkButton2" runat="server" CommandName="Delete">Delete</asp:LinkButton>
                            </ItemTemplate>
                           
                       </asp:TemplateField>
                </Columns>
            </asp:GridView>
    </div>
    </form>
</body>
</html>


showDetail.aspx.cs


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.IO;

public partial class showfileradiodroup : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        grid();
    }
    public void grid()
    {
        string con = @"Data Source=SQLDB;Initial Catalog=Demo;User ID=Demoh;Password=Demo1@";
        SqlConnection conn = new SqlConnection(con);
        string q = "select c.com_id,c.com_name,c.image,c.per_name,c.gender,s.statename,cc.city,c.com_ph,c.com_mo,c.com_add from pi_comp1 c INNER JOIN pi_statedemo s ON c.state=s.id INNER JOIN pi_citydemo cc ON c.city=cc.cid";
        //string q ="select * from pi_comp1";
        DataSet ds = new DataSet();
        SqlDataAdapter da = new SqlDataAdapter();
        SqlCommand cmd1 = new SqlCommand(q, conn);
        conn.Open();
        da.SelectCommand = cmd1;

        cmd1.ExecuteNonQuery();
        da.Fill(ds);
        GridView1.DataSource = ds;
        GridView1.DataBind();
          
        conn.Close();
    }
    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {
        Label cid = (Label)GridView1.Rows[e.NewEditIndex].FindControl("Label8");
        Response.Redirect("~/fileradiodroupexample.aspx?c_id=" + cid.Text + "");
    }
    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        Label cid = (Label)GridView1.Rows[e.RowIndex].FindControl("Label8");
        string con = @"Data Source=SQLDB;Initial Catalog=Demo;User ID=Demoh;Password=Demo1@";
        SqlConnection conn = new SqlConnection(con);
        string q = "delete from pi_comp1 where com_id='" + cid.Text + "'";


        SqlCommand cmd1 = new SqlCommand(q, conn);
        conn.Open();


        cmd1.ExecuteNonQuery();
        GridView1.EditIndex = -1;
        grid();



        conn.Close();
    }
}





0 comments :