Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:
ASP.NET
<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'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
HTML
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)
C#
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.
Posted
Comments
Prasad Khandekar 26-Jan-15 14:06pm    
Hello Sana,

Have a look at below example.
http://www.codeproject.com/Articles/706078/Popup-Editing-Adding-Deleting-Records-with-GridVie
http://www.aspsnippets.com/Articles/Add-Edit-Update-Records-in-GridView-using-Modal-Popup-in-ASP.Net.aspx
Did you debug? Where is the exact issue?
Sana Farooq (Sana Qureshi) 27-Jan-15 7:23am    
well i have no idea where the issue is, but it's not producing the required result.
Please debug line by line. You will get to know for sure.
Sana Farooq (Sana Qureshi) 27-Jan-15 10:32am    
can you please tell how i can do that? i have never done debugging before.

1 solution

C#
int rowIndex = int.Parse(e.CommandArgument.ToString());
string val = (string)this.grid.DataKeys[rowIndex]["myKey"];
 
Share this answer
 
Comments
Sana Farooq (Sana Qureshi) 27-Jan-15 8:03am    
Where do i put this code? can u please explain it to me a bit? what's "myKey"
Amresh Bahadur Singh 28-Jan-15 0:57am    
here mykey is your DataKeyNames="ID".
Sana Farooq (Sana Qureshi) 28-Jan-15 8:25am    
Thank you!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900