|
|
Databind DataGrid
|
From ".Net Frenzy" on 10/10/2006 4:25:25 AM
|
Hi Guys,
I am developing a webpart for Sharepoint. I have a databinded dropdownlist which databinds from an existing Sharepoint List.
Now, when the user makes a selection in this DropDownList, I want that a DataGrid should be populated. Now this DataGrid also databinds to another existing Sharepoint List.
Any ideas, how I can achieve this. Don't worry about Postbacks or populating datagrid, I have allready sorted that out.
Please HELP...
At the moment I am doing this. Private Sub DataGrid_BindData ' Datagrid Properties myDG = New DataGrid myDG.GridLines = GridLines.Both myDG.AutoGenerateColumns = False myDG.Enabled = True myDG.EnableViewState = True
' Column - 1 Dim bCol As New BoundColumn bCol.HeaderText = "Sample " bCol.DataField = myDDL.SelectedValue '<-- here i am passing the selected item of ' of dropdownlist. This style is not working. dgBookings.Columns.Add(bCol) End Sub
What should I do
|
|
|
|
Re: Databind DataGrid
|
From "S.S. Ahmed" on 10/13/2006 9:56:35 AM
|
Does simply calling datagrid.Bind() not work? Because datagrid is already bound to a SPS list, you just need to call the bind() in OnSelected() of your first drop down. It should work!
-- S.S. Ahmed www.walisystems.com
".Net Frenzy" wrote in message news:1160479525.726699.271440@e3g2000cwe.googlegroups.com... > Hi Guys, > > I am developing a webpart for Sharepoint. I have a databinded > dropdownlist which databinds from an existing Sharepoint List. > > Now, when the user makes a selection in this DropDownList, I want that > a DataGrid should be populated. Now this DataGrid also databinds to > another existing Sharepoint List. > > Any ideas, how I can achieve this. Don't worry about Postbacks or > populating datagrid, I have allready sorted that out. > > Please HELP... > > At the moment I am doing this. > Private Sub DataGrid_BindData > ' Datagrid Properties > myDG = New DataGrid > myDG.GridLines = GridLines.Both > myDG.AutoGenerateColumns = False > myDG.Enabled = True > myDG.EnableViewState = True > > ' Column - 1 > Dim bCol As New BoundColumn > bCol.HeaderText = "Sample " > bCol.DataField = myDDL.SelectedValue '<-- here i am passing the > selected item of > ' of > dropdownlist. This style is not working. > dgBookings.Columns.Add(bCol) > End Sub > > What should I do >
|
|
|
|
Re: Databind DataGrid
|
From ".Net Frenzy" on 10/13/2006 3:09:57 AM
|
Dear Ahmed,
If i try to do simply datagrid.Bind() then the whole contents of SPS list is retrieved. I want that if a user selects let's say Room 1 from DropDownList, he then presses a button called "Show Events" then the datagrid should be populated with relevant details for only Room 1 which is ONLY those entries from SPS list which have Room 1 in their "Room Title" Column.
By doing simply datagrid.Bind(), it recalls everything from SPS list. I don't understand how to achieve this because normally you can simply pass a argument while databinding and the relevant details can be recalled from database or array or any module function. How will SPS List know that I want a particular list rows. How to pass this information,,,
Don't know what to do please help and suggest..
Thanks ---------------------
|
|
|
|
Re: Databind DataGrid
|
From "S.S. Ahmed" on 10/14/2006 5:04:46 PM
|
A nice post that shows you an example on using SPQuery object:
http://blog.u2u.info/DottextWeb/patrick/archive/2004/10/27/291.aspx
Regards,
-- SSA www.walisystems.com
-- ".Net Frenzy" wrote in message news:1160734197.149683.63710@m7g2000cwm.googlegroups.com... > Dear Ahmed, > > If i try to do simply datagrid.Bind() then the whole contents of SPS > list is retrieved. I want that if a user selects let's say Room 1 from > DropDownList, he then presses a button called "Show Events" then the > datagrid should be populated with relevant details for only Room 1 > which is ONLY those entries from SPS list which have Room 1 in their > "Room Title" Column. > > By doing simply datagrid.Bind(), it recalls everything from SPS list. I > don't understand how to achieve this because normally you can simply > pass a argument while databinding and the relevant details can be > recalled from database or array or any module function. How will SPS > List know that I want a particular list rows. How to pass this > information,,, > > Don't know what to do please help and suggest.. > > Thanks > --------------------- >
|
|
|
|
Re: Databind DataGrid
|
From ".Net Frenzy" on 10/16/2006 7:40:48 AM
|
Hi Ahmed,
Sorry, i posted twice because I had to find a solution urgently. I am working on the post you recommended. Please can you throw any light on how can I add item to a Sharepoint List programatically.
I want to add dropDownList selection to list but just doesn't work. If I add value from Textbox then it works but not Dropdownlist. Here have a look.
Dim newItem As SPListItem = itemCollection.Add newItem("Title") = txtBox.Text newItem("Venue") = myDDL.selectedValue.ToString newItem.Update()
I dont know why dropdownlist value fails to be inserted in SPlist. I want to add user selection to the SPList.
What am I doin wrong.???? PLEASE SUGGEST...........! ----------------------------------
|
|
|
|
Re: Databind DataGrid
|
From "S.S. Ahmed" on 10/17/2006 12:42:51 PM
|
Do you actually get a value in myDDL.selectedValue.ToString?
Hint:
Try myDDL.selectedItem.Text.ToString()
value must be set in the option tag, eg, otherwise you will get nothing in the selectedValue().
-- S.S. Ahmed www.walisystems.com
".Net Frenzy" wrote in message news:1161009648.828542.211500@i3g2000cwc.googlegroups.com... > Hi Ahmed, > > Sorry, i posted twice because I had to find a solution urgently. I am > working on the post you recommended. Please can you throw any light on > how can I add item to a Sharepoint List programatically. > > I want to add dropDownList selection to list but just doesn't work. If > I add value from Textbox then it works but not Dropdownlist. Here have > a look. > > Dim newItem As SPListItem = itemCollection.Add > newItem("Title") = txtBox.Text > newItem("Venue") = myDDL.selectedValue.ToString > newItem.Update() > > I dont know why dropdownlist value fails to be inserted in SPlist. I > want to add user selection to the SPList. > > What am I doin wrong.???? > PLEASE SUGGEST...........! > ---------------------------------- >
|
|
|
|
Re: Databind DataGrid
|
From "Sujath" on 10/17/2006 1:00:21 AM
|
HI Frenzy,
Couldn't reply for your message, I was on vaction
Anyway you can use of SP Objects in this case
SPQuery will helpm you I guess. returns items from the existing list
Regards
Sujath kumar
S.S. Ahmed wrote: > Do you actually get a value in myDDL.selectedValue.ToString? > > Hint: > > Try myDDL.selectedItem.Text.ToString() > > value must be set in the option tag, eg, otherwise you will get nothing in the > selectedValue(). > > -- > S.S. Ahmed > www.walisystems.com > > > ".Net Frenzy" wrote in message > news:1161009648.828542.211500@i3g2000cwc.googlegroups.com... > > Hi Ahmed, > > > > Sorry, i posted twice because I had to find a solution urgently. I am > > working on the post you recommended. Please can you throw any light on > > how can I add item to a Sharepoint List programatically. > > > > I want to add dropDownList selection to list but just doesn't work. If > > I add value from Textbox then it works but not Dropdownlist. Here have > > a look. > > > > Dim newItem As SPListItem = itemCollection.Add > > newItem("Title") = txtBox.Text > > newItem("Venue") = myDDL.selectedValue.ToString > > newItem.Update() > > > > I dont know why dropdownlist value fails to be inserted in SPlist. I > > want to add user selection to the SPList. > > > > What am I doin wrong.???? > > PLEASE SUGGEST...........! > > ---------------------------------- > >
|
|
|
|
Re: Databind DataGrid
|
From ".Net Frenzy" on 10/17/2006 3:38:20 AM
|
Hi Sujath and Ahmed, Man you guys are excellent. Your help has been very resourceful to me. Thank you very much. ------------------------------------
Hey Sujath, Welcome back from your vacation. Check out my other post too remember the Postback issue. About this one, Can you throw more light into SP Objects and SP Query. I don't know how to even go about it. -------------------------------------- Hey Ahmed, I tried your method myDDL.selectedItem.Text.ToString()
Let me just first say I have a dropdownlist, a checkbox and a textbox. Only new item adding is working for Textbox. After trying your method it gave me the error saying - "The field you are trying to update is Read Only. Don't understand why dropdownlist value and checkbox selection is not appending to the list.
newItem("ABC") = myDDL.selectedItem.Text.ToString() newItem("XYZ") = myCBox.checked newItem("MNO") = txtTitle.Text ' <- only this works
Please suggest what's happening.... Thanks ------------------------------------
|
|
|
|
Re: Databind DataGrid
|
From ".Net Frenzy" on 10/17/2006 3:39:10 AM
|
Hi Sujath and Ahmed, Man you guys are excellent. Your help has been very resourceful to me. Thank you very much. ------------------------------------
Hey Sujath, Welcome back from your vacation. Check out my other post too remember the Postback issue. About this one, Can you throw more light into SP Objects and SP Query. I don't know how to even go about it. -------------------------------------- Hey Ahmed, I tried your method myDDL.selectedItem.Text.ToString()
Let me just first say I have a dropdownlist, a checkbox and a textbox. Only new item adding is working for Textbox. After trying your method it gave me the error saying - "The field you are trying to update is Read Only. Don't understand why dropdownlist value and checkbox selection is not appending to the list.
newItem("ABC") = myDDL.selectedItem.Text.ToString() newItem("XYZ") = myCBox.checked newItem("MNO") = txtTitle.Text ' <- only this works
Please suggest what's happening.... Thanks ------------------------------------
|
|
|
|
Re: Databind DataGrid
|
From "S.S. Ahmed" on 10/17/2006 9:50:53 PM
|
What are the source items that you are trying to update with dropdown and checkbox values? Is field MNO a custom added field? What about ABC and XYZ fields? Are these custom added fields as well? Are you trying to update "Created By" field?
-SSA www.walisystems.com
".Net Frenzy" wrote in message news:1161081499.966570.203010@k70g2000cwa.googlegroups.com... > Hi Sujath and Ahmed, > Man you guys are excellent. > Your help has been very resourceful to me. Thank you very much. > ------------------------------------ > > Hey Sujath, Welcome back from your vacation. Check out my other post > too remember the Postback issue. About this one, Can you throw more > light into SP Objects and SP Query. I don't know how to even go about > it. > -------------------------------------- > Hey Ahmed, > I tried your method > myDDL.selectedItem.Text.ToString() > > Let me just first say I have a dropdownlist, a checkbox and a textbox. > Only new item adding is working for Textbox. After trying your method > it gave me the error saying - "The field you are trying to update is > Read Only. Don't understand why dropdownlist value and checkbox > selection is not appending to the list. > > newItem("ABC") = myDDL.selectedItem.Text.ToString() > newItem("XYZ") = myCBox.checked > newItem("MNO") = txtTitle.Text ' <- only this works > > Please suggest what's happening.... > Thanks > ------------------------------------ >
|
|
|
|
Re: Databind DataGrid
|
From ".Net Frenzy" on 10/18/2006 3:47:59 AM
|
Dear Ahmed,
Don't worry about it now. I have sorted it. I checked on MSDN to see what I was doing wrong. The only reason dropdownlist value was not being added is because it was a lookup field. So instead of doing just myDDL.DataTextField = "ABC", I had to add one line more
myDDL.datasource = dataset.Tables(0) myDDL.dataTextField = "ABC" myDDL.dataValueField = "ID" '<- this is the one myDDL.dataBind()
In this way i was able to add a new row to my SPList using a user interface. Since TextField has String so it will not allow user to add it programatically but as soon as you add the ValueField the thing worked, as in Sharepoint list they were identified using numerical values.
Thanks ahmed for all your help.
Now, I am stuck with a very stupid problem. When I use post back I am not able to retain the last selected value in my DropDownList. So everytime user has to select again and again.
Damn it, Microsoft should develop user interface development environment for Sharepoint too man, everything is boring and tiring.
Anyway, how can I do that. Regards, ----------------------------------------
|
|
|
|
Re: Databind DataGrid
|
From "S.S. Ahmed" on 10/18/2006 8:26:22 PM
|
Hi,
Glad to hear that you have sorted out the problem. You will notice that i gave you a hint in one of my previous messages. Here are my words:
"value must be set in the option tag" - I used HTML language, this is same as myDDL.dataValueField = "ID"
Also, in my last message, i asked you whether you were trying to update a "Created By" field? You can not update "Created By" and "Modified By" and lookup fields with user info with string values.
There are two ways to solve the postback problem:
1. Enable the "EnableViewState" property on the dropdown control.
2. Get the selectedItem in each post back and re-assign it to the dropdown control.
Regards,
-- S.S. Ahmed www.walisystems.com
".Net Frenzy" wrote in message news:1161168479.674302.199890@b28g2000cwb.googlegroups.com... > Dear Ahmed, > > Don't worry about it now. I have sorted it. I checked on MSDN to see > what I was doing wrong. The only reason dropdownlist value was not > being added is because it was a lookup field. So instead of doing just > myDDL.DataTextField = "ABC", I had to add one line more > > myDDL.datasource = dataset.Tables(0) > myDDL.dataTextField = "ABC" > myDDL.dataValueField = "ID" '<- this is the one > myDDL.dataBind() > > In this way i was able to add a new row to my SPList using a user > interface. Since TextField has String so it will not allow user to add > it programatically but as soon as you add the ValueField the thing > worked, as in Sharepoint list they were identified using numerical > values. > > Thanks ahmed for all your help. > > Now, I am stuck with a very stupid problem. When I use post back I am > not able to retain the last selected value in my DropDownList. So > everytime user has to select again and again. > > Damn it, Microsoft should develop user interface development > environment for Sharepoint too man, everything is boring and tiring. > > Anyway, how can I do that. > Regards, > ---------------------------------------- >
|
|
|
|
Re: Databind DataGrid
|
From ".Net Frenzy" on 10/19/2006 6:49:18 AM
|
Hi Ahmed,
Thanks for your suggestions.
I did try your way and it worked. I am not trying to update any "Created By" Field instead just add a row to this list. You see I have a column in a SPList that I have added myself. The only problem was since this column was a Lookup field, which you know that picked a value from another existing SPList, it became difficult for it to add the new row.
You are right we cant update any Created BY and LookUP field but I only wanted to add a record into SPList with whatever selection the user made. This did not mean any updations to existing rows.
Now about the postback, Solved it. Infact I had to set both of these to make it work. First I enabled the view state and then declared a class level variable that gets the dropdownlist value inside button click function. Then where my databind code was I re-assigned the value.
All in All it works fine now. Thanks......& Cheers..............! ----------------------------------------
Now, I would like your help on my biggest hurdle.
You see when you add something to the Events List in Sharepoint, it asks us about Begin and End, which is a date & Time. Now suppose you have a events list called "My Events" which contains information like Title, Begin, End, Description, etc...
Inside my code I open a Site, then a List and then a View and then load the view to a dataset. Here List - "My Events", View - "All Items"
I want to programatically check if a TimeSlot is available or not? If Yes then, append this new entry to SPList ( don't worry about this I have done this) If No, then don't worry about that too.
My Question is Ahmed, how do I query this dataset ?? Let's say we have an existing entry in "My Events", now If a Event Starts and Ends at 12:00 to 13:00 then if user selects 12:00 and 13:00 in 2 dropdownlists, the web part should tell me if it is available or not....
Hope you get what I am saying..
How can a dataset can be queried. I will wait for your reply first then I will also show you how I am doing it, My method works fine but sometimes......
Thanks a million....
|
|
|
|
Re: Databind DataGrid
|
From "S.S. Ahmed" on 10/20/2006 5:12:53 PM
|
Well, it depends on what is contained in your dataset. One way to check column names available in your dataset datatable is by opening a quick watch window with ds.tables(0).columns. Then you can assign values to the dropdown boxes:
ds = New DataSet ds = CType(HttpContext.Current.Application("ListData"), DataSet) ddlStartTime.DataSource = ds.Tables(0).Select("StartTime") ddlStartTime.DataTextField = ds.Tables(0).Columns("StartTime").ColumnName.ToString ddlStartTime.DataValueField = ds.Tables(0).Columns("StartTime").ColumnName.ToString ddlStartTime.DataBind()
Regards, -- S.S. Ahmed www.walisystems.com
".Net Frenzy" wrote in message news:1161265758.198333.77090@h48g2000cwc.googlegroups.com... > Hi Ahmed, > > Thanks for your suggestions. > > I did try your way and it worked. I am not trying to update any > "Created By" Field instead just add a row to this list. You see I have > a column in a SPList that I have added myself. The only problem was > since this column was a Lookup field, which you know that picked a > value from another existing SPList, it became difficult for it to add > the new row. > > You are right we cant update any Created BY and LookUP field but I only > wanted to add a record into SPList with whatever selection the user > made. This did not mean any updations to existing rows. > > Now about the postback, Solved it. Infact I had to set both of these to > make it work. First I enabled the view state and then declared a class > level variable that gets the dropdownlist value inside button click > function. Then where my databind code was I re-assigned the value. > > All in All it works fine now. Thanks......& Cheers..............! > ---------------------------------------- > > Now, I would like your help on my biggest hurdle. > > You see when you add something to the Events List in Sharepoint, it > asks us about Begin and End, which is a date & Time. Now suppose you > have a events list called "My Events" which contains information like > Title, Begin, End, Description, etc... > > Inside my code I open a Site, then a List and then a View and then load > the view to a dataset. Here List - "My Events", View - "All Items" > > I want to programatically check if a TimeSlot is available or not? If > Yes then, append this new entry to SPList ( don't worry about this I > have done this) If No, then don't worry about that too. > > My Question is Ahmed, how do I query this dataset ?? Let's say we have > an existing entry in "My Events", now If a Event Starts and Ends at > 12:00 to 13:00 then if user selects 12:00 and 13:00 in 2 dropdownlists, > the web part should tell me if it is available or not.... > > Hope you get what I am saying.. > > How can a dataset can be queried. I will wait for your reply first then > I will also show you how I am doing it, My method works fine but > sometimes...... > > Thanks a million.... >
|
|
|
|
Re: Databind DataGrid
|
From ".Net Frenzy" on 10/24/2006 3:58:20 AM
|
Hi Ahmed,
Thank you for all your constant support. Man, forget about querying the dataset, we can deal with that later, I will discuss that with you later. I am still unable to populate the datagrid with relevant data based upon the selections made by the user. Action Sequence. 1. Select Room 2. Click Button 3. Show Datagird with details
I did go through your CAML post but man honestly I have no experience in CAML so I was not able to do anything. Can you please suggest what should I do ??
Here have a look. myDDL is dropdownList and myDG is DataGrid. I bind the dropdownlist in a seprate function to a SPList. So myDDL contains Room 1, Room 2, Room 3 etc..
myDDL.DataSource = myDataSet.Tables(0) myDDL.DataTextField = "LinkTitle" myDDL.DataValueField = "ID" myDDL.DataBind() --------------------------------------------- this is datagrid in another function which will populate on button click. so this is inside button click function. I only want certain columns so bound columns not all so don't worry about this.
' Datagrid Properties myDG = New DataGrid myDG.GridLines = GridLines.Both myDG.Caption = "Details" myDG.AutoGenerateColumns = False
' Column - 1 Dim bCol As New BoundColumn bCol.HeaderText = "Venue" bCol.DataField = "Resource" bCol.ReadOnly = True dgBookings.Columns.Add(bCol) bCol = Nothing
myDG.DataSource = dsBookings.Tables(0) myDG.DataKeyField = drpRoom.SelectedValue.ToString '<-- Not working myDG.DataBind() -----------------------------------
What should I do ?? If I remove the datakeyField line then all works fine but the datagrid will show everything which I don't want.
How to pass to datagrid that it needs to bind to dropdownlist selected value.
Thanks,,,,,
S.S. Ahmed wrote: > Well, it depends on what is contained in your dataset. One way to check > column names available in your dataset datatable is by opening a quick watch > window with ds.tables(0).columns. Then you can assign values to the dropdown > boxes: > > ds = New DataSet > ds = CType(HttpContext.Current.Application("ListData"), DataSet) > ddlStartTime.DataSource = ds.Tables(0).Select("StartTime") > ddlStartTime.DataTextField = > ds.Tables(0).Columns("StartTime").ColumnName.ToString > ddlStartTime.DataValueField = > ds.Tables(0).Columns("StartTime").ColumnName.ToString > ddlStartTime.DataBind() > > Regards, > -- > S.S. Ahmed > www.walisystems.com > > > ".Net Frenzy" wrote in message > news:1161265758.198333.77090@h48g2000cwc.googlegroups.com... > > Hi Ahmed, > > > > Thanks for your suggestions. > > > > I did try your way and it worked. I am not trying to update any > > "Created By" Field instead just add a row to this list. You see I have > > a column in a SPList that I have added myself. The only problem was > > since this column was a Lookup field, which you know that picked a > > value from another existing SPList, it became difficult for it to add > > the new row. > > > > You are right we cant update any Created BY and LookUP field but I only > > wanted to add a record into SPList with whatever selection the user > > made. This did not mean any updations to existing rows. > > > > Now about the postback, Solved it. Infact I had to set both of these to > > make it work. First I enabled the view state and then declared a class > > level variable that gets the dropdownlist value inside button click > > function. Then where my databind code was I re-assigned the value. > > > > All in All it works fine now. Thanks......& Cheers..............! > > ---------------------------------------- > > > > Now, I would like your help on my biggest hurdle. > > > > You see when you add something to the Events List in Sharepoint, it > > asks us about Begin and End, which is a date & Time. Now suppose you > > have a events list called "My Events" which contains information like > > Title, Begin, End, Description, etc... > > > > Inside my code I open a Site, then a List and then a View and then load > > the view to a dataset. Here List - "My Events", View - "All Items" > > > > I want to programatically check if a TimeSlot is available or not? If > > Yes then, append this new entry to SPList ( don't worry about this I > > have done this) If No, then don't worry about that too. > > > > My Question is Ahmed, how do I query this dataset ?? Let's say we have > > an existing entry in "My Events", now If a Event Starts and Ends at > > 12:00 to 13:00 then if user selects 12:00 and 13:00 in 2 dropdownlists, > > the web part should tell me if it is available or not.... > > > > Hope you get what I am saying.. > > > > How can a dataset can be queried. I will wait for your reply first then > > I will also show you how I am doing it, My method works fine but > > sometimes...... > > > > Thanks a million.... > >
|
|
|
|
Re: Databind DataGrid
|
From "S.S. Ahmed" on 10/25/2006 2:37:53 PM
|
Hi,
DataKeyField property is used to specify the primary key field for the data being displayed in the DataGrid. Make sure that that field you have selected as a datakeyfield is unique.
-- S.S. Ahmed www.walisystems.com
".Net Frenzy" wrote in message news:1161687500.583889.327570@i42g2000cwa.googlegroups.com... > Hi Ahmed, > > Thank you for all your constant support. Man, forget about querying the > dataset, we can deal with that later, I will discuss that with you > later. I am still unable to populate the datagrid with relevant data > based upon the selections made by the user. Action Sequence. > 1. Select Room > 2. Click Button > 3. Show Datagird with details > > I did go through your CAML post but man honestly I have no experience > in CAML so I was not able to do anything. Can you please suggest what > should I do ?? > > Here have a look. myDDL is dropdownList and myDG is DataGrid. I bind > the dropdownlist in a seprate function to a SPList. So myDDL contains > Room 1, Room 2, Room 3 etc.. > > myDDL.DataSource = myDataSet.Tables(0) > myDDL.DataTextField = "LinkTitle" > myDDL.DataValueField = "ID" > myDDL.DataBind() > --------------------------------------------- > this is datagrid in another function which will populate on button > click. so this is inside button click function. I only want certain > columns so bound columns not all so don't worry about this. > > ' Datagrid Properties > myDG = New DataGrid > myDG.GridLines = GridLines.Both > myDG.Caption = "Details" > myDG.AutoGenerateColumns = False > > ' Column - 1 > Dim bCol As New BoundColumn > bCol.HeaderText = "Venue" > bCol.DataField = "Resource" > bCol.ReadOnly = True > dgBookings.Columns.Add(bCol) > bCol = Nothing > > myDG.DataSource = dsBookings.Tables(0) > myDG.DataKeyField = drpRoom.SelectedValue.ToString '<-- Not > working > myDG.DataBind() > ----------------------------------- > > What should I do ?? If I remove the datakeyField line then all works > fine but the datagrid will show everything which I don't want. > > How to pass to datagrid that it needs to bind to dropdownlist selected > value. > > Thanks,,,,, > > > S.S. Ahmed wrote: > > Well, it depends on what is contained in your dataset. One way to check > > column names available in your dataset datatable is by opening a quick watch > > window with ds.tables(0).columns. Then you can assign values to the dropdown > > boxes: > > > > ds = New DataSet > > ds = CType(HttpContext.Current.Application("ListData"), DataSet) > > ddlStartTime.DataSource = ds.Tables(0).Select("StartTime") > > ddlStartTime.DataTextField = > > ds.Tables(0).Columns("StartTime").ColumnName.ToString > > ddlStartTime.DataValueField = > > ds.Tables(0).Columns("StartTime").ColumnName.ToString > > ddlStartTime.DataBind() > > > > Regards, > > -- > > S.S. Ahmed > > www.walisystems.com > > > > > > ".Net Frenzy" wrote in message > > news:1161265758.198333.77090@h48g2000cwc.googlegroups.com... > > > Hi Ahmed, > > > > > > Thanks for your suggestions. > > > > > > I did try your way and it worked. I am not trying to update any > > > "Created By" Field instead just add a row to this list. You see I have > > > a column in a SPList that I have added myself. The only problem was > > > since this column was a Lookup field, which you know that picked a > > > value from another existing SPList, it became difficult for it to add > > > the new row. > > > > > > You are right we cant update any Created BY and LookUP field but I only > > > wanted to add a record into SPList with whatever selection the user > > > made. This did not mean any updations to existing rows. > > > > > > Now about the postback, Solved it. Infact I had to set both of these to > > > make it work. First I enabled the view state and then declared a class
> > > level variable that gets the dropdownlist value inside button click > > > function. Then where my databind code was I re-assigned the value. > > > > > > All in All it works fine now. Thanks......& Cheers..............! > > > ---------------------------------------- > > > > > > Now, I would like your help on my biggest hurdle. > > > > > > You see when you add something to the Events List in Sharepoint, it > > > asks us about Begin and End, which is a date & Time. Now suppose you > > > have a events list called "My Events" which contains information like > > > Title, Begin, End, Description, etc... > > > > > > Inside my code I open a Site, then a List and then a View and then load > > > the view to a dataset. Here List - "My Events", View - "All Items" > > > > > > I want to programatically check if a TimeSlot is available or not? If > > > Yes then, append this new entry to SPList ( don't worry about this I > > > have done this) If No, then don't worry about that too. > > > > > > My Question is Ahmed, how do I query this dataset ?? Let's say we have > > > an existing entry in "My Events", now If a Event Starts and Ends at > > > 12:00 to 13:00 then if user selects 12:00 and 13:00 in 2 dropdownlists, > > > the web part should tell me if it is available or not.... > > > > > > Hope you get what I am saying.. > > > > > > How can a dataset can be queried. I will wait for your reply first then > > > I will also show you how I am doing it, My method works fine but > > > sometimes...... > > > > > > Thanks a million.... > > > >
|
|
|
|
Re: Databind DataGrid
|
From "S.S. Ahmed" on 10/25/2006 2:47:46 PM
|
Hi,
DataKeyField property is used to specify the primary key field for the data being displayed in the DataGrid. Make sure that that field you have selected as a datakeyfield is unique and also make sure that the field is available in the dataset bound to the grid. For example, if datakeyfield is roomid then the roomid must be available in the dataset bound to the grid.
Another hint: Check the value of drpRoom.selectedvalue.ToString() in debugger. If it contains something like "#1;roomname" then you need to split this value and use the integer part only as the ID. If you dont do it, you will always get an error. These are two value separated by a semi colon. First part is integer ID and the second part is string value.
Hope this helps.
Regards,
-- S.S. Ahmed www.walisystems.com
".Net Frenzy" wrote in message news:1161687500.583889.327570@i42g2000cwa.googlegroups.com... > Hi Ahmed, > > Thank you for all your constant support. Man, forget about querying the > dataset, we can deal with that later, I will discuss that with you > later. I am still unable to populate the datagrid with relevant data > based upon the selections made by the user. Action Sequence. > 1. Select Room > 2. Click Button > 3. Show Datagird with details > > I did go through your CAML post but man honestly I have no experience > in CAML so I was not able to do anything. Can you please suggest what > should I do ?? > > Here have a look. myDDL is dropdownList and myDG is DataGrid. I bind > the dropdownlist in a seprate function to a SPList. So myDDL contains > Room 1, Room 2, Room 3 etc.. > > myDDL.DataSource = myDataSet.Tables(0) > myDDL.DataTextField = "LinkTitle" > myDDL.DataValueField = "ID" > myDDL.DataBind() > --------------------------------------------- > this is datagrid in another function which will populate on button > click. so this is inside button click function. I only want certain > columns so bound columns not all so don't worry about this. > > ' Datagrid Properties > myDG = New DataGrid > myDG.GridLines = GridLines.Both > myDG.Caption = "Details" > myDG.AutoGenerateColumns = False > > ' Column - 1 > Dim bCol As New BoundColumn > bCol.HeaderText = "Venue" > bCol.DataField = "Resource" > bCol.ReadOnly = True > dgBookings.Columns.Add(bCol) > bCol = Nothing > > myDG.DataSource = dsBookings.Tables(0) > myDG.DataKeyField = drpRoom.SelectedValue.ToString '<-- Not > working > myDG.DataBind() > ----------------------------------- > > What should I do ?? If I remove the datakeyField line then all works > fine but the datagrid will show everything which I don't want. > > How to pass to datagrid that it needs to bind to dropdownlist selected > value. > > Thanks,,,,, > > > S.S. Ahmed wrote: > > Well, it depends on what is contained in your dataset. One way to check > > column names available in your dataset datatable is by opening a quick watch > > window with ds.tables(0).columns. Then you can assign values to the dropdown > > boxes: > > > > ds = New DataSet > > ds = CType(HttpContext.Current.Application("ListData"), DataSet) > > ddlStartTime.DataSource = ds.Tables(0).Select("StartTime") > > ddlStartTime.DataTextField = > > ds.Tables(0).Columns("StartTime").ColumnName.ToString > > ddlStartTime.DataValueField = > > ds.Tables(0).Columns("StartTime").ColumnName.ToString > > ddlStartTime.DataBind() > > > > Regards, > > -- > > S.S. Ahmed > > www.walisystems.com > > > > > > ".Net Frenzy" wrote in message > > news:1161265758.198333.77090@h48g2000cwc.googlegroups.com... > > > Hi Ahmed, > > > > > > Thanks for your suggestions. > > > > > > I did try your way and it worked. I am not trying to update any > > > "Created By" Field instead just add a row to this list. You see I have > > > a column in a SPList that I have added myself. The only problem was > > > since this column was a Lookup field, which you know that picked a > > > value from another existing SPList, it became difficult for it to add > > > the new row. > > > > > > You are right we cant update any Created BY and LookUP field but I only > > > wanted to add a record into SPList with whatever selection the user > > > made. This did not mean any updations to existing rows. > > > > > > Now about the postback, Solved it. Infact I had to set both of these to > > > make it work. First I enabled the view state and then declared a class > > > level variable that gets the dropdownlist value inside button click > > > function. Then where my databind code was I re-assigned the value. > > > > > > All in All it works fine now. Thanks......& Cheers..............! > > > ---------------------------------------- > > > > > > Now, I would like your help on my biggest hurdle. > > > > > > You see when you add something to the Events List in Sharepoint, it > > > asks us about Begin and End, which is a date & Time. Now suppose you > > > have a events list called "My Events" which contains information like > > > Title, Begin, End, Description, etc... > > > > > > Inside my code I open a Site, then a List and then a View and then load > > > the view to a dataset. Here List - "My Events", View - "All Items" > > > > > > I want to programatically check if a TimeSlot is available or not? If > > > Yes then, append this new entry to SPList ( don't worry about this I > > > have done this) If No, then don't worry about that too. > > > > > > My Question is Ahmed, how do I query this dataset ?? Let's say we have > > > an existing entry in "My Events", now If a Event Starts and Ends at > > > 12:00 to 13:00 then if user selects 12:00 and 13:00 in 2 dropdownlists, > > > the web part should tell me if it is available or not.... > > > > > > Hope you get what I am saying.. > > > > > > How can a dataset can be queried. I will wait for your reply first then > > > I will also show you how I am doing it, My method works fine but > > > sometimes...... > > > > > > Thanks a million.... > > > >
|
|
|
|
Re: Databind DataGrid
|
From ".Net Frenzy" on 10/26/2006 4:10:46 AM
|
Hi Ahmed,
I tried this first while debugging like you suggested myDG.DataKeyField = myDDL.SelectedValue When I query this line it shows the accurate value that is selected by user. I confirmed this by viewing the source of the webpart, it showed exact values for each item in dropdownlist. This is the source code option selected="selected" value="7"> Room 1
This did not work regardless of the fact that accurate value is being passed to perform binding. If I select Room 1 then while debugging it showed the value "7". Not working...!
Then, I tried doing something like this.
myDG.DataSource = myDataSet.Tables(0).select("Title = "' & myDDL.SelectedValue & "' ") here, I don't do anything with DataKeyField. This "Title" is XML tag to point to Room Title. I extracted XML to understand the individual items.
Nothing seems to be working. What am I doing wrong ?? ----------------------------
|
|
|
|
Re: Databind DataGrid
|
From "S.S. Ahmed" on 10/27/2006 1:37:47 PM
|
Hi,
If you are sure that there is nothing wrong with your passing of value then check your datagrid declaration code. It should be something like this:
AutoGenerateColumns="False" AlternatingItemStyle-BackColor="#eeeeee" HeaderStyle-BackColor="Navy" HeaderStyle-ForeColor="White" HeaderStyle-Font-Size="15pt" HeaderStyle-Font-Bold="True" DataKeyField="RoomID">
Note the datakeyfield, it should be a roomid! and this roomid must be available in your dataset that you will use with your datagrid. If there is no roomid in your dataset, then you will always get an error message. If everything is ok in declaration part, then use the following line to assign a value:
myDG.DataKeyField = myDDL.SelectedValue myDG.bind()
For the second part of your question, I think there is a mistake. Datagrid's datasource property is used to bind datagrid to a data source which is usually a table. Looking at the line you are using, does myDDL.SelectedValue contain a table name? You say that myDDL.SelectedValue contains a room title, then how is it going to work? You need to provide a valid table index or name in datasource property! The correct syntax is as following:
myDG.Datasource = myDataSet.Tables(0) myDG.datakeyfield = myDDL.SelectedValue myDG.Bind()
-- S.S. Ahmed www.walisystems.com
".Net Frenzy" wrote in message news:1161861046.109545.186110@b28g2000cwb.googlegroups.com... > Hi Ahmed, > > I tried this first while debugging like you suggested > myDG.DataKeyField = myDDL.SelectedValue > When I query this line it shows the accurate value that is selected by > user. I confirmed this by viewing the source of the webpart, it showed > exact values for each item in dropdownlist. > This is the source code > option selected="selected" value="7"> Room 1 > > > > > This did not work regardless of the fact that accurate value is being > passed to perform binding. If I select Room 1 then while debugging it > showed the value "7". Not working...! > > Then, I tried doing something like this. > > myDG.DataSource = myDataSet.Tables(0).select("Title = "' & > myDDL.SelectedValue > & "' ") > here, I don't do anything with DataKeyField. This "Title" is XML tag to > point to Room Title. I extracted XML to understand the individual > items. > > Nothing seems to be working. What am I doing wrong ?? > ---------------------------- >
|
|
|
|
Re: Databind DataGrid
|
From "S.S. Ahmed" on 10/27/2006 1:53:57 PM
|
Hi,
If you are sure that there is nothing wrong with your passing of value then check your datagrid declaration code. It should be something like this:
AutoGenerateColumns="False" AlternatingItemStyle-BackColor="#eeeeee" HeaderStyle-BackColor="Navy" HeaderStyle-ForeColor="White" HeaderStyle-Font-Size="15pt" HeaderStyle-Font-Bold="True" DataKeyField="RoomID">
Note the datakeyfield, it should be a roomid! and this roomid must be available in your dataset that you will use with your datagrid. If there is no roomid in your dataset, then you will always get an error message. If everything is ok in declaration part, then use the following line to assign a value:
myDG.DataKeyField = myDDL.SelectedValue myDG.bind()
For the second part of your question, I think there is a mistake. Datagrid's datasource property is used to bind datagrid to a data source which is usually a table. Looking at the line you are using, does myDDL.SelectedValue contain a table name? You say that myDDL.SelectedValue contains a room title, then how is it going to work? You need to provide a valid table index or name in datasource property! The correct syntax is as following:
myDG.Datasource = myDataSet.Tables(0) myDG.datakeyfield = myDDL.SelectedValue myDG.Bind()
-- S.S. Ahmed www.walisystems.com
".Net Frenzy" wrote in message news:1161861046.109545.186110@b28g2000cwb.googlegroups.com... > Hi Ahmed, > > I tried this first while debugging like you suggested > myDG.DataKeyField = myDDL.SelectedValue > When I query this line it shows the accurate value that is selected by > user. I confirmed this by viewing the source of the webpart, it showed > exact values for each item in dropdownlist. > This is the source code > option selected="selected" value="7"> Room 1 > > > > > This did not work regardless of the fact that accurate value is being > passed to perform binding. If I select Room 1 then while debugging it > showed the value "7". Not working...! > > Then, I tried doing something like this. > > myDG.DataSource = myDataSet.Tables(0).select("Title = "' & > myDDL.SelectedValue > & "' ") > here, I don't do anything with DataKeyField. This "Title" is XML tag to > point to Room Title. I extracted XML to understand the individual > items. > > Nothing seems to be working. What am I doing wrong ?? > ---------------------------- >
|
|
|
|
Re: Databind DataGrid
|
From ".Net Frenzy" on 10/31/2006 4:06:00 AM
|
Hi Ahmed,
Still not able to do it. I don't know what to do? Can you please write a CAML query that I can just cut, copy paste on my code. Here is the values. myDDL - dropdownlist, myDG - datagrid
Please write everything this means like all the proper syntax because I wont be able to deal with any errors because of the lack of experience.
I still don't understand why myDG.DataSource = myDataset.Tables(0) myDG.DataKeyField = myDDL.SelectedValue myDG.bind() is failing to retrieve the relevant information. What am i doing wrong ? All I want is to databind a datagrid with a databinded dropdownlist. Damn it, i have tried everything nothing is working.. By the way in the above line of code the error i receive is - DataBinder.Eval: 'System.DataRowView' does not contain a property with the name 7. ------------- 7 is Room 1 when you do Alt + V and View Source on sharepoint site that has my web part. So, i mean if the value is being passed why datagrid is not receiving it from datasource..?
Help.. yet again...
|
|
|
|
Re: Databind DataGrid
|
From "S.S. Ahmed" on 10/31/2006 9:40:38 PM
|
It seems to be a very minor problem that i am unable to figure out. DataBinder.Eval error occurs when you are trying to display something that is not understood by the control. In this case, datagrid seems to have a problem with the selectedvalue. Try this again:
myDG.DataKeyField = myDDL.SelectedValue.ToString()
Did you check your datagrid definition? Does it contain the datakeyfield set to roomid?
Regards,
-- S.S. Ahmed www.walisystems.com
".Net Frenzy" wrote in message news:1162296360.711086.286190@m73g2000cwd.googlegroups.com... > Hi Ahmed, > > Still not able to do it. I don't know what to do? Can you please write > a CAML query that I can just cut, copy paste on my code. Here is the > values. > myDDL - dropdownlist, myDG - datagrid > > Please write everything this means like all the proper syntax because I > wont be able to deal with any errors because of the lack of experience. > > > I still don't understand why > myDG.DataSource = myDataset.Tables(0) > myDG.DataKeyField = myDDL.SelectedValue > myDG.bind() > is failing to retrieve the relevant information. What am i doing wrong > ? All I want is to databind a datagrid with a databinded dropdownlist. > Damn it, i have tried everything nothing is working.. By the way in the > above line of code the error i receive is - DataBinder.Eval: > 'System.DataRowView' does not contain a property with the name 7. > ------------- > 7 is Room 1 when you do Alt + V and View Source on sharepoint site that > has my web part. So, i mean if the value is being passed why datagrid > is not receiving it from datasource..? > > Help.. yet again... >
|
|
|
|
Re: Databind DataGrid
|
From "S.S. Ahmed" on 10/31/2006 9:43:43 PM
|
Also try this:
myDG.DataKeyField = Convert.ToInt(myDDL.SelectedValue.ToString());
-- S.S. Ahmed www.walisystems.com
".Net Frenzy" wrote in message news:1162296360.711086.286190@m73g2000cwd.googlegroups.com... > Hi Ahmed, > > Still not able to do it. I don't know what to do? Can you please write > a CAML query that I can just cut, copy paste on my code. Here is the > values. > myDDL - dropdownlist, myDG - datagrid > > Please write everything this means like all the proper syntax because I > wont be able to deal with any errors because of the lack of experience. > > > I still don't understand why > myDG.DataSource = myDataset.Tables(0) > myDG.DataKeyField = myDDL.SelectedValue > myDG.bind() > is failing to retrieve the relevant information. What am i doing wrong > ? All I want is to databind a datagrid with a databinded dropdownlist. > Damn it, i have tried everything nothing is working.. By the way in the > above line of code the error i receive is - DataBinder.Eval: > 'System.DataRowView' does not contain a property with the name 7. > ------------- > 7 is Room 1 when you do Alt + V and View Source on sharepoint site that > has my web part. So, i mean if the value is being passed why datagrid > is not receiving it from datasource..? > > Help.. yet again... >
|
|