Thanks a lot, here is the working code for anyone else to reference
<asp:DataGrid id="gridBO" runat="server" OnEditCommand="gridBO_Edit
<ItemStyle font-name="Arial" font-size="10pt" forecolor="#000000" />
<HeaderStyle font-name="Arial" font-size="12pt" font-bold="true" backcolor="#658bbc" forecolor="#FFFFFF" />
<AlternatingItemStyle font-name="Arial" font-size="10pt" backcolor="#e3efff" />
<Columns>
<asp:TemplateColumn>
<HeaderTemplate>
Status
</HeaderTemplate>
<ItemTemplate>
<%# DataBinder.Eval(Container.
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList id="ddlStatus" runat="server" SelectedIndex='<%# getStatusIndex(DataBinder.
<asp:ListItem>IN</asp:List
<asp:ListItem>OUT</asp:Lis
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="employeeName" HeaderText="Name" ReadOnly="true" />
<asp:BoundColumn DataField="employeePhone" HeaderText="Phone" ReadOnly="true" />
<asp:BoundColumn DataField="employeeComment
<asp:EditCommandColumn EditText="Edit" CancelText="Cancel" UpdateText="Update" />
</Columns>
</asp:DataGrid>
**************************
using System;
using System.Collections;
using System.IO;
using System.Configuration;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OleDb;
using System.Data.SqlClient;
public class InOut : Page
{
public Label lblStatus;
public DropDownList ddlStatus;
public DataGrid gridBO;
public string sqlStatement1 = "Select * FROM Employee WHERE employeeDepartmentId = 1 ORDER BY employeeDepRank";
protected void page_load(Object s, EventArgs e)
{
if(!IsPostBack)
{
BindData();
}
}
public int getStatusIndex(string statusName)
{
if(statusName == "IN")
{
return 1;
} else {
return 0;
}
}
protected void BindData()
{
OleDbConnection objConn = new OleDbConnection(Configurat
OleDbCommand objCmd = new OleDbCommand(sqlStatement1
objConn.Open();
OleDbDataReader objRdr = objCmd.ExecuteReader();
gridBO.DataSource = objRdr;
gridBO.DataBind();
objRdr.Close();
objConn.Close();
}
protected void gridBO_Edit(Object s, DataGridCommandEventArgs e)
{
gridBO.EditItemIndex = e.Item.ItemIndex;
BindData();
}
protected void gridBO_Cancel(Object s, DataGridCommandEventArgs e)
{
gridBO.EditItemIndex = -1;
BindData();
}
protected void gridBO_Update(Object s, DataGridCommandEventArgs e)
{
int employeeDepRank = (int)gridBO.DataKeys[e.Ite
string strStatus = ((DropDownList)e.Item.Find
string strComments = ((TextBox)e.Item.Cells[3].
string strCmd = "UPDATE Employee Set employeeStatus='" + strStatus + "', employeeComments='" + strComments + "' WHERE employeeDepRank=" + employeeDepRank;
OleDbConnection objConn = new OleDbConnection(Configurat
OleDbCommand objCmd = new OleDbCommand(strCmd, objConn);
objConn.Open();
objCmd.ExecuteNonQuery();
objConn.Close();
gridBO.EditItemIndex = -1;
BindData();
}
Main Topics
Browse All Topics





by: brdrokPosted on 2007-07-06 at 11:40:34ID: 19433996
hi,
DataItem, "InOut") %> //assuming this is the name of your database column
urValueFie ldIs" DataTextField="WhatEverYou rTextField Is"
what you need is to make use of the <asp:TemplateColumn>. kinda looks like this:
<asp:TemplateColumn HeaderText="In/Out">
<ItemTemplate>
<%# DataBinder.Eval(Container.
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList runat="server" id="ddlInOut" DataValueField="WhatEverYo
DataSource='<%# GetYesNoValues() %>'
</EditItemTemplate>
</asp:TemplateColumn>
I don't know if this 100% correct or not...but it defn. should point you in the right direction. Good luck and god's speed.