Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Mar 17th, 2005, 1:25 PM   #1
wright45
Newbie
 
Join Date: Jan 2005
Posts: 5
Rep Power: 0 wright45 is on a distinguished road
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?
wright45 is offline   Reply With Quote
Old Jun 19th, 2005, 11:46 AM   #2
ykasan
Newbie
 
Join Date: Jun 2005
Location: NJ
Posts: 2
Rep Power: 0 ykasan is on a distinguished road
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
Attached Files
File Type: zip BindControls.zip (29.0 KB, 34 views)

Last edited by ykasan; Jun 19th, 2005 at 12:03 PM.
ykasan is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 2:57 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC