YAFLogo

new4net
  • new4net
  • 50.6% (Neutral)
  • YAF Forumling Topic Starter
12 years ago
I am new to Dot Net and I am basic knowledge of Grid view. I am trying to get some intermediate grid view knowledge. So please share and help me to get some knowledge.

I am trying to know Check box,dropdownlist and button are generated for each row in Grid view.I am using C# language.

If I checked the check box and button was clicked some action will happen, in between i true the property Autopostback of check box true, When check box is clicked the drop down list in the row should update the correct data for the row and if the button is clicked, the specific action is triggered, the selected row will display at the bottom of the page in nested grid view or separate grid view.

Please share you thoughts. For your convenience I have attached my 50% of code with this query.. I hope I will get the answer soon.

www.4shared.com/zip/n9yCLSV2/ltest.html

Sponsor
Chetan Bavarva
8 years ago
use this source code for add a CheckBox DropDownList to gridview

Default.aspx

You can insert a CheckBox control inside a GridView by using TemplateField.


<form id="form" runat="server">
  <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">     
        <Columns>
            <asp:TemplateField>
                <ItemTemplate>
                    <asp:CheckBox ID="chkCtrl" runat="server" />
                </ItemTemplate>
            </asp:TemplateField>           
        </Columns>
    </asp:GridView>
</form>

C# Source Code


  protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            SqlDataAdapter adapter = new SqlDataAdapter();
            DataSet ds = new DataSet();
            string sql = null;
            string connetionString = "Data Source=.;Initial Catalog=pubs;User ID=sa;Password=password";
            sql = "select stor_id,customerName from Customer";
            SqlConnection connection = new SqlConnection(connetionString);
            connection.Open();
            SqlCommand command = new SqlCommand(sql, connection);
            adapter.SelectCommand = command;
            adapter.Fill(ds);
            adapter.Dispose();
            command.Dispose();
            connection.Close();
            GridView.DataSource = ds.Tables[0];
            GridView.DataBind();
        }
    }

Default.aspx

You can insert a dropdownlist control inside a GridView by using EditItemTemplate.


<form id="form" runat="server">
<asp:TemplateField HeaderText="customerName" SortExpression="customerName">
                <EditItemTemplate>
                                <asp:DropDownList ID="DropDownList" runat="server"
                                                DataSourceID="SqlDataSource2" DataTextField="customerName" DataValueField="customerName"
                                                SelectedValue='<%# Bind("customerName") %>'>
                                </asp:DropDownList>
                </EditItemTemplate>
                <ItemTemplate>
                                <asp:Label ID="Label" runat="server" Text='<%# Bind("customerName") %>'></asp:Label>
                </ItemTemplate>
</asp:TemplateField>
<asp:SqlDataSource ID="SqlDataSource" runat="server"
                ConnectionString="<%$ ConnectionStrings:SQLDbConnection %>"
                SelectCommand="SELECT DISTINCT [customerName] FROM [Customer]"></asp:SqlDataSource>
</form>    

Chetan Patel

Custom software company India 

iFour Technolab Pvt. Ltd