how to select entire row from grid view in c# asp.net and bind to textbox field

Posted by Raj_chennai under ASP.NET on 1/27/2012 | Points: 10 | Views : 13179 | Status : [Member] | Replies : 6
i need in Grid View selected cell value bind in textbox

raj


Responses

Posted by: Blessyjees on: 1/27/2012 [Member] Bronze | Points: 25

Up
0
Down
Hi,

Not clear. Do you want insert selected value from grid view to text box.

Blessy Baby
Digitalmesh Softech pvt Ltd
https://blessybaby.wordpress.com/

Raj_chennai, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Raj_chennai on: 1/27/2012 [Member] Starter | Points: 25

Up
0
Down
hi,
i want to insert selected values from grid view to text boxes

raj

Raj_chennai, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Mittaikariss on: 1/28/2012 [Member] Bronze | Points: 25

Up
0
Down
First Select Row in Datagridview and then Click Edit or Add Button.

Web Application U can using gridview value pass method through URL:


Window Form Coding

this is form1 coding:


 if (dataGridView1.SelectedRows.Count > 0)

{
branch_details_edit.brcode = Convert.ToString(dataGridView1.SelectedRows[0].Cells[1].Value);
branch_details_edit.brname = Convert.ToString(dataGridView1.SelectedRows[0].Cells[2].Value);
branch_details_edit.brcontactper = Convert.ToString(dataGridView1.SelectedRows[0].Cells[3].Value);
branch_details_edit.braddress = Convert.ToString(dataGridView1.SelectedRows[0].Cells[4].Value);
branch_details_edit.brpfg = Convert.ToString(dataGridView1.SelectedRows[0].Cells[5].Value);
branch_details_edit.brptg = Convert.ToString(dataGridView1.SelectedRows[0].Cells[6].Value);
branch_details_edit.brestgr = Convert.ToString(dataGridView1.SelectedRows[0].Cells[7].Value);
branch_details_edit bde = new branch_details_edit();
bde.brediteventhandler += new EventHandler(refreshbranch);
bde.ShowDialog();
}
else
{
MessageBox.Show("Please Select any Row", "" + Login_payroll.user + "", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
}

and Following Code to form2
 public static string brcode, brname, brcontactper, braddress, brpfg, brptg, brestgr;


private void branch_details_edit_Load(object sender, EventArgs e)
{
txtbranchcodeedit.Text = brcode;
txtbranchnameedit.Text = brname;
txtcpedit.Text = brcontactper;
txtaddressedit.Text = braddress;
txtpfgredit.Text = brpfg;
txtptgroedit.Text = brptg;
txtestgredit.Text = brestgr;
}





http://www.invomtech.com/

....sundarsowmia....

Raj_chennai, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Mittaikariss on: 1/28/2012 [Member] Bronze | Points: 25

Up
0
Down

In ASP.Net

First Bind Gridview Data From SQL And Add Hyperlink in Gridview

 <a href="get.aspx?del=1&pn=<%Response.Write(dr["productnumber"].ToString());%>"></a>


Here Pass Value From Gridview To Same Page

Now We Are Writing Page Load following code, We Can get Value From Url using Querystring function


string pn= Request.QueryString["pn"];

string b= Request.QueryString["del"];
if (b == "1")
{
System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection();
con.ConnectionString = ConfigurationManager.ConnectionStrings["crm"].ToString();
con.Open();
System.Data.SqlClient.SqlCommand cmd1 = new System.Data.SqlClient.SqlCommand("select * from dbo.master_productdetails where productnumber='" + pn + "'", con);
System.Data.SqlClient.SqlDataReader dr1 = cmd1.ExecuteReader();
while (dr1.Read())
{
TextBox1.Text = dr1["productname"].ToString();
TextBox2.Text = dr1["brandname"].ToString();
TextBox3.Text = dr1["productnumber"].ToString();
TextBox4.Text = dr1["inward_date"].ToString();
TextBox5.Text = dr1["product_color"].ToString();
TextBox6.Text = dr1["amount"].ToString();
}
dr1.Close();
}



http://www.invomtech.com/

....sundarsowmia....

Raj_chennai, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Mageshinfo on: 2/3/2012 [Member] Starter | Points: 25

Up
0
Down
Pass multiple data from grid view to textboxes in samepage

.aspx page

<asp:GridView ID="gvTechnicians" runat="server" CellPadding="4" ForeColor="#333333" Width="345px" 

GridLines="None" AutoGenerateColumns="false" CssClass="gridtxt" >
<RowStyle BackColor="#e8f1fa" />
<FooterStyle BackColor="#1d7bd2" Font-Bold="True" ForeColor="#fbfbfb" />
<PagerStyle BackColor="#1d78cb" ForeColor="#fbfbfb" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#e8f1fa" Font-Bold="True" ForeColor="#5d5c5c" />
<HeaderStyle BackColor="#1a72cb" Font-Bold="True" ForeColor="#fbfbfb" />
<EditRowStyle BackColor="#176ac6" />
<AlternatingRowStyle BackColor="#fbfbfb" />
<Columns>
<asp:TemplateField HeaderText="Name">
<ItemTemplate>
<asp:Label ID="lblName" runat="server" Text='<%#Eval("Name") %>' ></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Title">
<ItemTemplate>
<asp:Label ID="lblUsername" runat="server" Text='<%#Eval("Title") %>' ></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="">
<ItemTemplate>
<a href="../Forms/Technicians.aspx?del=1&name=<%Response.Write(dr1["name"].ToString());%>"></a>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

.aspx.cs page

OleDbCommand cmd = new OleDbCommand();

OleDbDataAdapter da = new OleDbDataAdapter();
DataSet ds = new DataSet();
string query;
OleDbConnection conn = new OleDbConnection(ConfigurationManager.ConnectionStrings["dbcon"].ConnectionString);
protected void Page_Load(object sender, EventArgs e)
{
loadgrid();
loadvalue();
}
public void loadgrid()
{
if (conn.State == ConnectionState.Closed)
conn.Open();
query = "select Name,Title from TblTechnician";
cmd = new OleDbCommand(query, conn);
da = new OleDbDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds, "TblTechnician");
gvTechnicians.DataSource = ds.Tables[0];
gvTechnicians.DataBind();
conn.Close();
}
public void loadvalue()
{
string name = Request.QueryString["name"];
string b = Request.QueryString["del"];
if (b == "1")
{
conn.Open();
OleDbCommand cmd = new OleDbCommand("select Name,Title from TblTechnician where Name='"+name+"'",conn);
OleDbDataReader dr1 = cmd.ExecuteReader();
while (dr1.Read())
{
txtCompanyname.Text = dr1["Name"].ToString();
txtAvgcost.Text = dr1["Title"].ToString();
}
dr1.Close();
}


kindly check my coding and give correct solution.

P.Magesh
Software Engineer
Colan Infotech

Raj_chennai, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Priyagoel_24 on: 8/24/2013 [Member] Starter | Points: 25

Up
0
Down
hello friend
, I think you want to check if excel data is already in DB. In this case check if data already
exists before insert it. Here is the code which might work in this case:
string check = "select name,days,hdays,months,years * from inventory";
//ad.Fill(dt1);
//string _where = "select * from inventory where name= 'priya' + dt1.Rows[i]
[name].ToString()where days = 'days + Convert.ToInt32(dt1.Rows[i][days]' where hdays ='hdays
+Convert.ToInt32(dt1.Rows[i][hdays]' where months = 'monthhs +Convert.ToInt32(dt1.Rows[i]
[months]))";
tell me

Regard
Priya

Raj_chennai, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response