Click here to Skip to main content
15,905,414 members
Home / Discussions / ASP.NET
   

ASP.NET

 
GeneralRe: URI Format Not Supported. Pin
Meetu Choudhary11-Sep-09 2:03
Meetu Choudhary11-Sep-09 2:03 
GeneralRe: URI Format Not Supported. Pin
Meetu Choudhary11-Sep-09 2:46
Meetu Choudhary11-Sep-09 2:46 
Questiondropdownlist in datagrid Pin
m@dhu10-Sep-09 21:31
m@dhu10-Sep-09 21:31 
AnswerRe: dropdownlist in datagrid Pin
Christian Graus10-Sep-09 21:44
protectorChristian Graus10-Sep-09 21:44 
AnswerRe: dropdownlist in datagrid Pin
Christian Graus10-Sep-09 21:59
protectorChristian Graus10-Sep-09 21:59 
GeneralRe: dropdownlist in datagrid Pin
m@dhu10-Sep-09 22:07
m@dhu10-Sep-09 22:07 
GeneralRe: dropdownlist in datagrid Pin
Christian Graus10-Sep-09 22:22
protectorChristian Graus10-Sep-09 22:22 
GeneralRe: dropdownlist in datagrid Pin
m@dhu10-Sep-09 22:35
m@dhu10-Sep-09 22:35 
this is complete code what i did.
i am able to access drop list with list items from another table..(dptmnt).
i need to select a list item for each row and should be updated with other columns when i click update link.....

<pre>
SqlConnection cnn = new SqlConnection("Data Source=NETZOOM\\MADHUK_2005;Integrated Security=SSPI;Initial Catalog=master");
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
BindData();

}
private void BindData()
{
SqlCommand cmd = new SqlCommand("employee", cnn);
cmd.Parameters.Add(new SqlParameter("@Employee_Name", SqlDbType.VarChar, 20));
cmd.Parameters["@Employee_Name"].Value = "Employee_Name";
cmd.Parameters.Add(new SqlParameter("@position", SqlDbType.VarChar, 20));
cmd.Parameters["@position"].Value = "position";
cmd.Parameters.Add(new SqlParameter("@Team_Name", SqlDbType.VarChar, 20));
cmd.Parameters["@Team_Name"].Value = "Team_Name";
cmd.Parameters.Add(new SqlParameter("@Employee_Id", SqlDbType.VarChar, 20));
cmd.Parameters["@Employee_Id"].Value = 1;
cmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter ad1 = new SqlDataAdapter(cmd);
string sql = "select dept from dptmnt";
DataSet ds = new DataSet(sql);

ad1.Fill(ds, "employe");
cnn.Open();
cmd.ExecuteNonQuery();
cnn.Close();
DataGid1.DataSource = ds;
DataGid1.DataBind();

}



protected void DataGid1_EditCommand(object source, DataGridCommandEventArgs e)
{



DataGid1.EditItemIndex = e.Item.ItemIndex;
BindData();
}


}
protected void DataGid1_CancelCommand(object source, DataGridCommandEventArgs e)
{
DataGid1.EditItemIndex = -1;
BindData();
}
protected void DataGid1_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{

System.Web.UI.WebControls.TextBox Employee_Name = new System.Web.UI.WebControls.TextBox();
Employee_Name = (System.Web.UI.WebControls.TextBox)e.Item.Cells[1].Controls[1];
System.Web.UI.WebControls.TextBox position = new System.Web.UI.WebControls.TextBox();
position = (System.Web.UI.WebControls.TextBox)e.Item.Cells[2].Controls[1];
System.Web.UI.WebControls.TextBox Team_Name = new System.Web.UI.WebControls.TextBox();
Team_Name = (System.Web.UI.WebControls.TextBox)e.Item.Cells[3].Controls[1];
System.Web.UI.WebControls.TextBox Employee_Id = new System.Web.UI.WebControls.TextBox();
Employee_Id = (System.Web.UI.WebControls.TextBox)e.Item.Cells[4].Controls[1];


SqlCommand cmd = new SqlCommand();
cmd.Connection = cnn;
cmd.CommandText = "update employe set Employee_Name=@Employee_Name,position=@position,Team_Name=@Team_Name where Employee_Id=@Employee_Id";
cmd.Parameters.Add(new SqlParameter("@Employee_Name", SqlDbType.VarChar, 20));
cmd.Parameters["@Employee_Name"].Value = Employee_Name.Text;
cmd.Parameters.Add(new SqlParameter("@position", SqlDbType.VarChar, 20));
cmd.Parameters["@position"].Value = position.Text;
cmd.Parameters.Add(new SqlParameter("@Team_Name", SqlDbType.VarChar, 20));
cmd.Parameters["@Team_Name"].Value = Team_Name.Text;
cmd.Parameters.Add(new SqlParameter("@Employee_Id", SqlDbType.VarChar, 20));
cmd.Parameters["@Employee_Id"].Value = Employee_Id.Text;
cnn.Open();
cmd.ExecuteNonQuery();
cnn.Close();
DataGid1.EditItemIndex = -1;
BindData();

}
protected void DataGid1_SelectedIndexChanged(object sender, EventArgs e)
{

DataGid1.SelectedIndex = -1;
BindData();
}
protected void DataGid1_DeleteCommand(object source, DataGridCommandEventArgs e)
{

SqlCommand cmd = new SqlCommand();

cmd.Connection = cnn;
cmd.CommandText = "Delete employe where Employee_Id='@Employee_Id'";
cnn.Open();
cmd.ExecuteNonQuery();
DataGid1.EditItemIndex = -1;
BindData();
}





protected void DataGid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{


string sql = "select dept from dptmnt";
DataSet ds = new DataSet();
SqlCommand cmd = new SqlCommand(sql, cnn);
cmd.Connection.Open();
SqlDataReader dr = cmd.ExecuteReader();


if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
DropDownList DropDownList1 = (DropDownList)((DataGridItem)e.Item).FindControl("DropDownList1");
ListItem li = new ListItem();
DropDownList1.Items.Add(li);
DropDownList1.DataSource = dr;
DropDownList1.DataValueField = "dept";
DropDownList1.DataTextField = "dept";
DropDownList1.DataBind();
cmd.Connection.Close();

}
}

</pre>
GeneralRe: dropdownlist in datagrid Pin
Christian Graus10-Sep-09 22:39
protectorChristian Graus10-Sep-09 22:39 
GeneralRe: dropdownlist in datagrid Pin
m@dhu10-Sep-09 22:44
m@dhu10-Sep-09 22:44 
GeneralRe: dropdownlist in datagrid Pin
Christian Graus10-Sep-09 22:48
protectorChristian Graus10-Sep-09 22:48 
GeneralRe: dropdownlist in datagrid Pin
m@dhu10-Sep-09 22:56
m@dhu10-Sep-09 22:56 
GeneralRe: dropdownlist in datagrid Pin
Christian Graus11-Sep-09 0:54
protectorChristian Graus11-Sep-09 0:54 
QuestionHow to get Mac Address. ?? Pin
Priyagdpl10-Sep-09 21:07
Priyagdpl10-Sep-09 21:07 
AnswerRe: How to get Mac Address. ?? Pin
Manas Bhardwaj10-Sep-09 21:40
professionalManas Bhardwaj10-Sep-09 21:40 
AnswerRe: How to get Mac Address. ?? Pin
Abhishek Sur10-Sep-09 22:24
professionalAbhishek Sur10-Sep-09 22:24 
QuestionFrench language support in aspx page Pin
GauravKP10-Sep-09 20:51
professionalGauravKP10-Sep-09 20:51 
AnswerRe: French language support in aspx page Pin
Christian Graus10-Sep-09 20:54
protectorChristian Graus10-Sep-09 20:54 
Questionbreak point not working Pin
myinstincts10-Sep-09 20:25
myinstincts10-Sep-09 20:25 
AnswerRe: break point not working Pin
N a v a n e e t h10-Sep-09 20:52
N a v a n e e t h10-Sep-09 20:52 
GeneralRe: break point not working Pin
myinstincts10-Sep-09 20:57
myinstincts10-Sep-09 20:57 
GeneralRe: break point not working Pin
Christian Graus10-Sep-09 21:00
protectorChristian Graus10-Sep-09 21:00 
AnswerRe: break point not working Pin
mr_muskurahat10-Sep-09 21:03
mr_muskurahat10-Sep-09 21:03 
AnswerRe: break point not working Pin
Abhishek Sur10-Sep-09 22:20
professionalAbhishek Sur10-Sep-09 22:20 
QuestionUpdate panel in asp.net Pin
anushh10-Sep-09 20:00
anushh10-Sep-09 20:00 

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.