I configure the gridview's datasource at run time and set the AutoGenerateColumns property to False. How do I add the specific columns to the gridview? thanks
Try something like GridView1.Columns.Add(DataControlFieldValue).
Randy
Mr. Randy what do you mean by DataControlFieldValue? Is the name of the field in the stored proceure? thanks:)
This is the column that you want to add. It has to be of the type DataControlFieldValue. You will have to build this control yourself. Take a look at msdn.microsoft.com and search on GridView, ASP.NET, 2.0, column and you should find the related articles on how to do something like this.
Sorry I'm so terse at the moment, but I'm late for an appointment. If you can't find this, let me know and I'll see if I can help later when I return.
Randy
I can already select specific columns from my stored procedure, thanks to your help
This is my code:
da.Fill(ds, "spu_LeavesHistoryList_PerEmployeePerYear")
Me.GridView1.DataSource = ds
Me.GridView1.DataMember = "spu_LeavesHistoryList_PerEmployeePerYear"
Me.GridView1.DataBind()
Me.GridView1.AutoGenerateColumns = FalseDim s_LeaveID As BoundField = New BoundField
s_LeaveID.DataField = "fxKeyLeaveID"
s_LeaveID.HeaderText = "Leave ID"Me.GridView1.Columns.Clear()
Me.GridView1.Columns.Add(s_LeaveID)Me.GridView1.DataKeyNames = Me.GridView1.Columns(s_LeaveID)
Apparently, Im having a problem setting the datakeyname of my gridview, this error appears for the blue-font line... value of type 'System.Web.UI.Controls.BoundField' cannot be converted to 'Integer'. So how do i actually set the datakeyname programmatically? thanks again.
You'll need to do something like this:
0
![]()
RGBraze 5/22/2006 6:28:31 PM
Thank you very much RGBraze!Youve been a BIG help
Can I assign multiple DataKeyNames for a gridview? thanks
Yep. Separate them by commas, is my understanding.
RGBraze:Yep. Separate them by commas, is my understanding.I have the following code:
Dim KeyName_LeaveID() As String = {"fxKeyLeaveID"}
Dim KeyName_KeyEmployee() As String = {"fcLastName"}Me.GridView1.DataKeyNames = "KeyName_LeaveID, KeyName_KeyEmployee"
But it produces an error:
"Value of type 'String' cannot be converted to '1-dimensional array of string'"
Sorry. Wasn't paying attention. Just change the key stuff to something like this:
Dim KeyNames As String = "{fxKeyLeaveID", "fcLastName"}
Then you can say GridView1.DataKeyNames = KeyNames and you should be fine.
Randy
Thank you very much Mr. Randy!
You've been a great help
dan
hello sir
Can i add template column in gridview...
plz reply....
Bhaarat
Remember to click "Mark as Answer" on the post that helps U
My Blog
hi Bhaarat, I'm sorry but I haven't tried that yet...