|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
How can I find the datakey of currently selected row?I searched for this and found an answer, but it did not help. In my
GridView there is a fileupload and a button click event to save the file upload. I am naming the file uploaded after the primary key field of my table, so, if I have employeeid 4, then my file name is 4.jpg. What I cannot do is reference that current employeeid. If click edit, my edittemplate show and my fileupload and button are visible. In that buttons event, I need the employee id of that row. I'm not sure how to get that. Thank you for any help. On 10/16/06 14:32, needin4mat***@gmail.com wrote:
> I searched for this and found an answer, but it did not help. In my If you have the current selected index (GridView1.SelectedIndex) you can> GridView there is a fileupload and a button click event to save the > file upload. I am naming the file uploaded after the primary key field > of my table, so, if I have employeeid 4, then my file name is 4.jpg. > > What I cannot do is reference that current employeeid. If click edit, > my edittemplate show and my fileupload and button are visible. In that > buttons event, I need the employee id of that row. > > I'm not sure how to get that. > > Thank you for any help. > do this: GridView1.Rows[GridView1.SelectedIndex].Cells[1].Text; Where '1' is the 0-based index of the grid view cell that contains your column. There may be a way to access the desired column by column name, but I'm new to ASP.NET and haven't found a way to do that yet. If anyone knows how, I would sure like to know ;-) Hi from Lima - Perú
Dim D1 As DataKey, CadSQL As String D1 = GridView1.SelectedDataKey CadSQL = D1("employeeid") good luck <needin4mat***@gmail.com> escribió en el mensaje Show quoteHide quote news:1161034346.346368.149840@k70g2000cwa.googlegroups.com... >I searched for this and found an answer, but it did not help. In my > GridView there is a fileupload and a button click event to save the > file upload. I am naming the file uploaded after the primary key field > of my table, so, if I have employeeid 4, then my file name is 4.jpg. > > What I cannot do is reference that current employeeid. If click edit, > my edittemplate show and my fileupload and button are visible. In that > buttons event, I need the employee id of that row. > > I'm not sure how to get that. > > Thank you for any help. > I actually tried this yesterday before my post, but I keep getting an
object reference error: DataKey d1 = null; string empID = null; d1 = GridView1.SelectedDataKey; empID = Convert.ToString(d1["EmployeeID"]); Response.Write("Empid: " + empID); EmployeeID is indeed one of the datakeynames in the grid. I cannot figure out why I get Object reference not set to an instance of an object. Thanks for any help. Daniel Yafac wrote: Show quoteHide quote > Hi from Lima - Perú > > Dim D1 As DataKey, CadSQL As String > > D1 = GridView1.SelectedDataKey > > CadSQL = D1("employeeid") > > good luck > > <needin4mat***@gmail.com> escribió en el mensaje > news:1161034346.346368.149840@k70g2000cwa.googlegroups.com... > >I searched for this and found an answer, but it did not help. In my > > GridView there is a fileupload and a button click event to save the > > file upload. I am naming the file uploaded after the primary key field > > of my table, so, if I have employeeid 4, then my file name is 4.jpg. > > > > What I cannot do is reference that current employeeid. If click edit, > > my edittemplate show and my fileupload and button are visible. In that > > buttons event, I need the employee id of that row. > > > > I'm not sure how to get that. > > > > Thank you for any help. > > needin4mat***@gmail.com wrote:
> I searched for this and found an answer, but it did not help. In my After much searching here is what I did:> GridView there is a fileupload and a button click event to save the > file upload. I am naming the file uploaded after the primary key field > of my table, so, if I have employeeid 4, then my file name is 4.jpg. > > What I cannot do is reference that current employeeid. If click edit, > my edittemplate show and my fileupload and button are visible. In that > buttons event, I need the employee id of that row. > > I'm not sure how to get that. > > Thank you for any help. if (e.CommandName == "addImage") { int index = Convert.ToInt32(e.CommandArgument); GridViewRow row = (GridViewRow)((Control)e.CommandSource).Parent.Parent; FileUpload fileUpload = (FileUpload) GridView1.Rows[row.RowIndex].FindControl("FileUpload1"); if (fileUpload.HasFile) { fileUpload.SaveAs(Server.MapPath(".\\images\\") + e.CommandArgument + ".jpg");//get employeeid } else { Response.Write("No File Uploaded."); } } Where e.CommandArgument is assigned when the control is built by CommandArgument='<%# Eval("employeeid")%>' The commandargument holds the data for my file and the commandsource parent(s) hold the row value so that I know what row clicked the upload button.
what' wrong with this?
how to map the given name to different domain FormView problem with Templates and Tables Turning URL Navigation off on a Treeview Help! Menu control not rendering properly on production Gridview: Edit row validation sqldatasource and connection exception handling ITemplate web parts bug? DataSource failing with null integer parameter |
|||||||||||||||||||||||