![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Jan 2005
Posts: 5
Rep Power: 0
![]() |
DropDownList in DataGrid not working!
Why doesn't this work....
I have... <asp:datagrid id=viewRequestDG runat="server" Width="100%" AutoGenerateColumns="False" DataMember="ShowRequest" DataSource="<%# viewRequestDS1 %>" OnEditCommand="EditClick" OnDeleteCommand="DeleteClick" OnUpdateCommand="SaveClick" OnCancelCommand="CancelClick"> ... <EditItemTemplate> <asp:DropDownList id=ddlStatus DataSource="<%# PopulateList() %>" Runat="server"> </asp:DropDownList> </EditItemTemplate> in my .aspx file then the functions... public void SaveClick(object sender, DataGridCommandEventArgs e)
{
DropDownList ddl = (DropDownList)e.Item.Cells[6].FindControl("ddlStatus");
DataRow row = viewRequestDS1.Tables["Request"].Rows[e.Item.ItemIndex];
row.ItemArray.SetValue(ddl.SelectedItem.Value.ToString(),7);
//row.ItemArray[7] = ddl.SelectedItem.Value.ToString();
RequestDA.Update(viewRequestDS1,"Request");
viewRequestDG.EditItemIndex = -1;
UpdateViewRequestDG();
}
public void EditClick(object sender, DataGridCommandEventArgs e)
{
viewRequestDG.EditItemIndex = e.Item.ItemIndex;
viewRequestDG.DataBind();
}
public string[] PopulateList()
{
string[] status = {"Hold", "Declined", "Accepted", "Paid"};
return status;
}in the .aspx.cs file... When I click the "Edit" Linkbutton, everything works fine. I see my dropdownlist with the right entries in the corresponding row. But when I select an entry from the dropdownlist and click save two problems happen... in the line with row.ItemArray.SetValue(ddl.SelectedItem.Value.ToString(),7); the ddl.SelectedItem.Value is always "Hold" or the 0 index, no matter what value I select in the DropDownList... Also in this line... The row.ItemArray.SetValue function doesn't work. It doesn't change the value of that cell in the DataSet... I have also tried... row.ItemArray[7] = ddl.SelectedItem.Value.ToString(); and this doesn't change row.ItemArray[7] either. Can anyone help? |
|
|
|
|
|
#2 |
|
Newbie
Join Date: Jun 2005
Location: NJ
Posts: 2
Rep Power: 0
![]() |
ItemArray problem
ItemArray in DataTable serves the different purpose.
To change a column value in DataTable use the following technique: DataTable dt = (DataTable)dataGrid1.DataSource; DataRow rCurrent = dt.Rows.Find("col11"); rCurrent[3]="Test"; dt.AcceptChanges(); Or if you still want to use ArrayList then you should use this: DataTable dt=(DataTable)dataGrid1.DataSource; DataRow rCurrent = dt.Rows.Find("col11"); object[] test = new object[4]{"1","2","3","4"}; rCurrent.ItemArray=test; dt.AcceptChanges(); For your convinience I added a sample c# project which demonstrates all of the abowe. Sincerely, Yuri Last edited by ykasan; Jun 19th, 2005 at 12:03 PM. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|