Click here to Skip to main content
15,891,204 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How can I get values of a datagridview selected row when button click on next form textboxes
Please any one help me.
Posted
Comments
Sandeep Mewara 16-Jul-12 3:04am    
Can you elaborate more on what have you tried so far and where are you stuck?
rockpune 16-Jul-12 3:11am    
i have two form in first form have textboxs and one save button
and in second form datagridview when i select on particular row on button click i have to show that row values into next form of textboxes for update
Mohamed Mitwalli 16-Jul-12 4:30am    
Share your code
[no name] 16-Jul-12 8:59am    
if (!IsPostBack)
{
DataTable dt1 = null;
DataRow[] dr = null;
DataTable dt2 = null;
DataRow[] dr2 = null;

try
{
FillCountry();

JavaScriptCalls();

if (HttpContext.Current.Request.QueryString.HasKeys())
{
btnSubmit.Text = "Update";
hdnId.Value = Request.QueryString[0].ToString();
SqlParameter objParam = new SqlParameter("@ID", hdnId.Value);
DataTable dt = SqlHelper.ExecuteDataset(strConn, CommandType.StoredProcedure, "LoginDetails_Get", objParam).Tables[0];
txtFirstName.Text = dt.Rows[0][1].ToString();
txtLastName.Text = dt.Rows[0][2].ToString();
txtAddress1.Text = dt.Rows[0][3].ToString();
txtAddress2.Text = dt.Rows[0][4].ToString();
txtCity.Text = dt.Rows[0][5].ToString();
string strCountry = dt.Rows[0][7].ToString();
dt1 = (DataTable)ViewState["Country"];
dr = dt1.Select("CountryName='" + strCountry + "'");
ddlCountry.SelectedValue = dr[0][0].ToString();
ViewState["Country"] = null;
if (dt.Rows[0][7].ToString() == "India")
{
ddlState.Style.Add("display", "block");
FillStateDropDown();
string strState = dt.Rows[0][6].ToString();
dt2 = (DataTable)ViewState["State"];
dr2 = dt2.Select("StateName='" + strState + "'");
ddlState.SelectedValue = dr2[0][0].ToString();
ViewState["State"] = null;
txtState.Style.Add("display", "none");
}
else
{
ddlState.Style.Add("display", "none");
txtState.Text = dt.Rows[0][6].ToString();
txtState.Style.Add("display", "block");
}
txtZip.Text = dt.Rows[0][8].ToString();
txtEmail.Text = dt.Rows[0][9].ToString();
//txtPassword.Attributes.Add("value", dt.Rows[0][10].ToString());
//txtConfirmPassword.Attributes.Add("value", dt.Rows[0][10].ToString());
hdnPwd1.Value = dt.Rows[0][10].ToString();
}
}
catch (Exception ex)
{
lblStatus.Text = ex.Message;
}
}

I used Query string to send Id of the record selected for edit and populated data using that id..(retrieved record matching that Id from db.)
query string..
try
{
if (e.CommandName == "DeleteItem")
{
lblStatus.Text = DeleteRecord(strConn, Convert.ToInt16(e.CommandArgument), "LoginDetails_Delete");
grdView.DataSource = EmployeeDetails();
grdView.DataBind();
}
if (e.CommandName == "EditItem")
{
Response.Redirect("AddEmployee.aspx?IdValue=" + Convert.ToInt32(e.CommandArgument));
}

.aspx page

<asp:TemplateField HeaderText="Edit" ItemStyle-Width="2%" ItemStyle-HorizontalAlign="Center">
<itemtemplate>
<asp:ImageButton ID="ImageButton1" runat="server" CommandName='EditItem' CommandArgument='<%# Eval("ID") %>'
ImageUrl="Edit.gif" />


<asp:TemplateField HeaderText="Delete" ItemStyle-Width="2%" ItemStyle-HorizontalAlign="Center">
<itemtemplate>
<asp:ImageButton ID="ImageButton2" runat="server" CommandName='Del

Hi,

I am not sure what you were trying to ask, but as far as i understand you want the selected row data to be passed on to second form and you want to view that data on second form.

If above is the case then you can achieve it as shown in the example in the bellow link:

http://weblogs.asp.net/gurusarkar/archive/2010/04/28/binding-list-of-custom-class-to-gridview-or-listview-control.aspx[^]

You need to create a custom class for the data you want to view and need to pass that custom class object when you click the Button.

Regards,
Darshan.
 
Share this answer
 
 
Share this answer
 
v2

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