Click here to Skip to main content
15,897,187 members
Home / Discussions / ASP.NET
   

ASP.NET

 
Question[newbie] Pin
jon-8016-Jan-09 9:04
professionaljon-8016-Jan-09 9:04 
AnswerRe: [newbie] Pin
Christian Graus16-Jan-09 9:12
protectorChristian Graus16-Jan-09 9:12 
GeneralRe: [newbie] Pin
jon-8016-Jan-09 9:55
professionaljon-8016-Jan-09 9:55 
GeneralRe: [newbie] Pin
Christian Graus16-Jan-09 10:02
protectorChristian Graus16-Jan-09 10:02 
GeneralRe: [newbie] Pin
jon-8016-Jan-09 10:25
professionaljon-8016-Jan-09 10:25 
Questionimage problem Pin
netJP12L16-Jan-09 8:44
netJP12L16-Jan-09 8:44 
AnswerRe: image problem Pin
Guffa16-Jan-09 9:03
Guffa16-Jan-09 9:03 
Questiongetting row into textbox and update,delete in gridview Pin
mihirkul16-Jan-09 6:54
mihirkul16-Jan-09 6:54 
i have a grid view on which i m doing insert ,delete,edit operations.
i have created stored procedures for them in sql server 2005.

i created buttons for edit and delete in each row of gridview.
i am only using "rowcommand" event for editing and deleting operation.
on edit button click i want to insert cell values of row into textboxes in my webform outside gridview.
i have edit button outside on clicking which it enters textbox value in grid view..
HOW CAN I ACHIEVE THIS?

source code:-

@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>




<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="gvEmployee" DataKeyNames="PKemployeeID" runat="server" Style="z-index: 100;
left: 112px; position: absolute; top: 271px" Width="472px" OnSelectedIndexChanged="gvEmployee_SelectedIndexChanged" Height="46px" AutoGenerateColumns="False" OnRowCommand="gvEmployee_RowCommand">
<Columns>
<asp:BoundField DataField="FirstName" HeaderText="Fitst Name" />
<asp:BoundField DataField="LastName" HeaderText="Last Name" />
<asp:BoundField DataField="EmployeeID" HeaderText="Employee Id" />
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:LinkButton ID="Button1" runat="server" CausesValidation="false" CommandName="EDIT" CommandArgument='<%# Bind("PKemployeeID") %>'
Text="Edit" />
</ItemTemplate>
</asp:TemplateField>
<asp:ButtonField ButtonType="Button" Text="Delete" CommandName="DELETE" />
</Columns>
</asp:GridView>
&nbsp; &nbsp; &nbsp;

</div>
<asp:Label ID="Label1" runat="server" Style="z-index: 101; left: 233px; position: absolute;
top: 36px" Text="First Name "></asp:Label>
&nbsp;
<asp:TextBox ID="txtEmpId" runat="server" Style="z-index: 102; left: 353px; position: absolute;
top: 158px"></asp:TextBox>
&nbsp;
<asp:TextBox ID="txtFirstName" runat="server" Style="z-index: 103; left: 354px; position: absolute;
top: 35px"></asp:TextBox>
<asp:TextBox ID="txtlastname" runat="server" Style="z-index: 104; left: 354px; position: absolute;
top: 91px"></asp:TextBox>
<asp:Label ID="Label2" runat="server" Style="z-index: 105; left: 232px; position: absolute;
top: 159px" Text="EmployeeID"></asp:Label>
<asp:Label ID="Label3" runat="server" Style="z-index: 106; left: 233px; position: absolute;
top: 94px" Text="Last Name"></asp:Label>
<
<asp:Button ID="btnAdd" runat="server" Style="z-index: 109; left: 259px; position: absolute;
top: 214px" Text="Add" Width="88px" OnClick="btnAdd_Click"


/>
</form>
</body>
</html>




aspx.cs:-
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;


public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string connectionString = (string)ConfigurationManager.AppSettings["ConnectionString"];
SqlConnection sqlconn = new SqlConnection(connectionString);
SqlCommand sqlCommand = new SqlCommand("GetemployeeDetails",sqlconn);
sqlCommand.CommandType = CommandType.StoredProcedure;

DataSet ds = new DataSet();
SqlDataAdapter ada = new SqlDataAdapter(sqlCommand);
ada.Fill(ds);
gvEmployee.DataSource = ds;

gvEmployee.DataBind();

}



protected void gvEmployee_SelectedIndexChanged(object sender, EventArgs e)
{
int index = gvEmployee.SelectedIndex;



}
protected void btnAdd_Click(object sender, EventArgs e)
{
string connectionString = (string)ConfigurationManager.AppSettings["ConnectionString"];
SqlConnection sqlconn = new SqlConnection(connectionString);
SqlCommand cmd = new SqlCommand("insertemployee", sqlconn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@FirstName", txtFirstName.Text);
cmd.Parameters.AddWithValue("@LastName", txtlastname.Text);
cmd.Parameters.AddWithValue("@EmployeeID", txtEmpId.Text);
cmd.Connection.Open();
cmd.ExecuteNonQuery();
cmd.Connection.Close();

}

protected void gvEmployee_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "EDIT")
{

int intPkId = Convert.ToInt32(e.CommandArgument);
/* i dont know what to put here */



//LinkButton btnEdit = e.CommandSource as LinkButton;
//GridViewRow row = (GridViewRow)((LinkButton)e.CommandSource).NamingContainer;
//int index = Convert.ToInt32(gvEmployee.DataKeys[row.RowIndex].Value);
//txtFirstName.Text = row.Cells[1].Text.ToString();
}
}
}

mihirkul vikram

AnswerCP IGNORE -- THIRD TIME SAME QUESTION Pin
leckey16-Jan-09 8:27
leckey16-Jan-09 8:27 
Question[newbie] Controls have to be aligned Pin
jon-8016-Jan-09 4:56
professionaljon-8016-Jan-09 4:56 
AnswerRe: [newbie] Controls have to be aligned Pin
TylerBrinks16-Jan-09 5:01
TylerBrinks16-Jan-09 5:01 
AnswerRe: [newbie] Controls have to be aligned Pin
jon-8016-Jan-09 9:56
professionaljon-8016-Jan-09 9:56 
AnswerRe: [newbie] Controls have to be aligned Pin
Member 400159616-Jan-09 22:34
Member 400159616-Jan-09 22:34 
GeneralRe: [newbie] Controls have to be aligned [modified] Pin
jon-8018-Jan-09 8:28
professionaljon-8018-Jan-09 8:28 
QuestionAjax Update Pannel Pin
Member 400159616-Jan-09 1:55
Member 400159616-Jan-09 1:55 
AnswerRe: Ajax Update Pannel Pin
Paddy Boyd16-Jan-09 2:46
Paddy Boyd16-Jan-09 2:46 
AnswerRe: Ajax Update Pannel Pin
Abhijit Jana16-Jan-09 4:03
professionalAbhijit Jana16-Jan-09 4:03 
GeneralRe: Ajax Update Pannel Pin
Member 400159616-Jan-09 22:31
Member 400159616-Jan-09 22:31 
Questionsql ouery problem Pin
pragya_chaubisa16-Jan-09 1:20
pragya_chaubisa16-Jan-09 1:20 
AnswerRe: sql ouery problem Pin
Ashfield16-Jan-09 2:32
Ashfield16-Jan-09 2:32 
GeneralRe: sql ouery problem Pin
pragya_chaubisa19-Jan-09 0:53
pragya_chaubisa19-Jan-09 0:53 
GeneralRe: sql ouery problem Pin
Ashfield19-Jan-09 8:53
Ashfield19-Jan-09 8:53 
Questiongrid view display Pin
varsh1216-Jan-09 0:49
varsh1216-Jan-09 0:49 
AnswerRe: grid view display Pin
Jon Rista16-Jan-09 12:21
Jon Rista16-Jan-09 12:21 
Questionhow to remove dll reference in visual studio? Pin
mr_muskurahat16-Jan-09 0:44
mr_muskurahat16-Jan-09 0:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.