Ok so i have been trying and trying to solve this issue, but to no avail. Therefore, i am posting here. Please note that i am a self learner and don't really know things in depth, just trying to learn.. So please be gentle. Here is my aspx code:

<div class="gview">
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CssClass="gview" DataKeyNames="ID" DataSourceID="SqlDataSource1" OnRowCommand="GridView1_RowCommand">
    <Columns>
    <asp:CommandField ShowDeleteButton="True" ShowSelectButton="True" />
    <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True" SortExpression="ID" />
    <asp:BoundField DataField="PName" HeaderText="PName" SortExpression="PName" />
    <asp:BoundField DataField="Age" HeaderText="Age" SortExpression="Age" />
    <asp:BoundField DataField="ContactNum" HeaderText="ContactNum" SortExpression="ContactNum" />
    <asp:BoundField DataField="Gender" HeaderText="Gender" SortExpression="Gender" />
    <asp:BoundField DataField="TestName" HeaderText="TestName" SortExpression="TestName" />
    <asp:BoundField DataField="ReqDate" HeaderText="ReqDate" SortExpression="ReqDate" />
    <asp:BoundField DataField="RepDate" HeaderText="RepDate" SortExpression="RepDate" />
    <asp:BoundField DataField="Consultant" HeaderText="Consultant" SortExpression="Consultant" />
    </Columns>    
    </asp:GridView>   

    <div id="labels" >
    <asp:Label ID="Label1" runat="server" Text="Name:"></asp:Label> 

    <asp:Label ID="Label2" runat="server" Text="Gender:"></asp:Label>
    <asp:Label ID="Label3" runat="server" Text="Age:"></asp:Label>

    <asp:Label ID="Label4" runat="server" Text="Contact Number:"></asp:Label>
    <asp:Label ID="Label5" runat="server" Text="Requesting Date:"></asp:Label>

    <asp:Label ID="Label6" runat="server" Text="Report Date:"></asp:Label>

    <asp:Label ID="Label7" runat="server" Text="Test Name:"></asp:Label>

    <asp:Label ID="Label8" runat="server" Text="Consultant:"></asp:Label>

    <asp:Label ID="Label9" runat="server" Text="ID:"></asp:Label>
                        </div>             
                        <br />
    <div id="textboxes">

    <asp:TextBox ID="TextBox1" runat="server" Height="33px" Width="270px"></asp:TextBox>

    <asp:DropDownList ID="DropDownList1" runat="server" Height="25px" Width="270px">
    <asp:ListItem>Female</asp:ListItem>
    <asp:ListItem>Male</asp:ListItem>
    </asp:DropDownList>

    <asp:TextBox ID="TextBox2" runat="server" Height="33px" Width="270px"></asp:TextBox>

    <asp:TextBox ID="TextBox3" runat="server" Height="31px" Width="270px"></asp:TextBox>

    <asp:TextBox ID="TextBox4" runat="server" Height="28px" Width="270px"></asp:TextBox>

    <asp:CalendarExtender ID="TextBox4_CalendarExtender" runat="server" Enabled="True" TargetControlID="TextBox4"> </asp:CalendarExtender>

    <asp:TextBox ID="TextBox5" runat="server" Height="33px" Width="270px"></asp:TextBox>
    <asp:CalendarExtender ID="TextBox5_CalendarExtender" runat="server" Enabled="True" TargetControlID="TextBox5">
</asp:CalendarExtender>
<asp:ComboBox ID="ComboBox1" runat="server" MultiSelect="true" Height="25px" Width="270">
<asp:ListItem>ANA</asp:ListItem>
<asp:ListItem>ASMA</asp:ListItem>
<asp:ListItem>ASO-titres</asp:ListItem>
<asp:ListItem>ESR</asp:ListItem>
<asp:ListItem>CBC</asp:ListItem>
<asp:ListItem>Anti-double Stranded DNA ab</asp:ListItem>
<asp:ListItem>Urea</asp:ListItem>
<asp:ListItem>T3, T4, TSH</asp:ListItem>
<asp:ListItem>Uric Acid</asp:ListItem>
<asp:ListItem>Totel Iron binding</asp:ListItem>
<asp:ListItem>Lipid profile</asp:ListItem>
<asp:ListItem>INR</asp:ListItem>
<asp:ListItem>LFT&#39;s</asp:ListItem>
<asp:ListItem>RA Factor</asp:ListItem>
<asp:ListItem>Serum Iron</asp:ListItem>
<asp:ListItem>Serum Ferritin</asp:ListItem>
<asp:ListItem>Calcium, Phosphates</asp:ListItem>
</asp:ComboBox>

<asp:TextBox ID="TextBox6" runat="server" Height="25px" Width="270px"></asp:TextBox>
<asp:TextBox ID="TextBox7" runat="server"  Height="25px" Width="270px"></asp:TextBox>

What i am trying to do is, when i click on

Select (Auto Generated by SQL)

all the data in that particular row should be fetched in the respective fields for editing purposes, so that the user doesn't have to retype all the info. (textboxes, dropdownlist etc)

This is what i have done so far: (only giving the needed code)

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Select")
            {
                int i = Convert.ToInt32(e.CommandArgument);
                TextBox1.Text = GridView1.Rows[i].Cells[1].Text.ToString();
                DropDownList1.SelectedItem.Text = GridView1.Rows[i].Cells[2].Text.ToString();
                TextBox2.Text = GridView1.Rows[i].Cells[3].Text.ToString();
                TextBox3.Text = GridView1.Rows[i].Cells[4].Text.ToString();
                TextBox4.Text = GridView1.Rows[i].Cells[5].Text.ToString();
                TextBox5.Text = GridView1.Rows[i].Cells[6].Text.ToString();
                ComboBox1.Text = GridView1.Rows[i].Cells[7].Text.ToString();
                TextBox6.Text = GridView1.Rows[i].Cells[8].Text.ToString();
                TextBox7.Text = GridView1.Rows[i].Cells[0].Text.ToString();

            }
        }

Now IDK if this is right or not, but i learned it somewhere and tried to implement.. but to no avail. Any kind of help will be greatly appreciated. P.S.:The event is fired when i click on select, the page refreshes.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.