all groups > asp.net > january 2008 >
asp.net :
Need GridView Help
I'm displaying data in a GridView that allows user to select a row. When a button is clicked, I need to locate the selected row. The problem is that I need an ID value from the selected row, but I do not want to display that ID value in the grid. I tried creating a hidden column, but I can't seem to be able to access it when the button is clicked. (At least, hidden columns do not appear to show up in the Cells collection of the selected row.) Is there any way to get an ID for the selected row without displaying that ID to the user? Also, does anyone know if there's any way to populate a GridView control without using the DataSource property, by just programatically adding rows to the grid? Thanks. -- Jonathan Wood SoftCircuits Programming http://www.softcircuits.com
[quoted text, click to view] > Is there any way to get an ID for the selected row without displaying that > ID to the user?
Look into the DataKeyNames and DataKeys properties. [quoted text, click to view] > Also, does anyone know if there's any way to populate a GridView control > without using the DataSource property, by just programatically adding rows > to the grid?
I don't know if you can "just add rows" or not, but I do know that you can bind a GridView to pretty much anything (I don't know the specific interface(s) off the top of my head). So, you can just create a list of objects (for example) and bind that: List<MyObject> data = new List<MyObject>(); PopulateData(data); MyGridView.DataSource = data; MyGridView.DataBind(); MyObject can be any class with public properties. So each object instance is a "row" and each public property is (potentially) a "column". IMO, it's even easier than adding rows & columns "manually".
[quoted text, click to view] "Jonathan Wood" <jwood@softcircuits.com> wrote in message news:eXe3ZlkXIHA.3940@TK2MSFTNGP05.phx.gbl... > I'm displaying data in a GridView that allows user to select a row. When a > button is clicked, I need to locate the selected row. > > The problem is that I need an ID value from the selected row, but I do not > want to display that ID value in the grid. I tried creating a hidden > column, but I can't seem to be able to access it when the button is > clicked. (At least, hidden columns do not appear to show up in the Cells > collection of the selected row.)
Have you tried using CommandArgument and/or CommandName? The CommandArgument can be assigned to the button as can the CommandName. When you click the button, you'd have to catch it in the RowCommand Event. You can do your processing from there.
[quoted text, click to view] "Jonathan Wood" <jwood@softcircuits.com> wrote in message news:eXe3ZlkXIHA.3940@TK2MSFTNGP05.phx.gbl... > Is there any way to get an ID for the selected row without displaying that > ID to the user?
When the data is bound to the GridView, populate the button's CommandArgument property with the ID... However, there's no need to use a button if all you want is the user to be able to select a row: protected void MyGridView_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { e.Row.Style["cursor"] = "pointer"; e.Row.Attributes.Add("onclick", ClientScript.GetPostBackEventReference(MyGridView, "Select$" + e.Row.RowIndex.ToString())); } } protected void MyGridView_SelectedIndexChanged(object sender, EventArgs e) { Response.Redirect("OtherPage.aspx?ID=" + MyGridView.SelectedValue.ToString(), false); } -- Mark Rae ASP.NET MVP http://www.markrae.net
Scott, [quoted text, click to view] > Look into the DataKeyNames and DataKeys properties.
Okay, I saw those but they seemed more database related. I see what they do now. [quoted text, click to view] > I don't know if you can "just add rows" or not, but I do know that you can > bind a GridView to pretty much anything (I don't know the specific > interface(s) off the top of my head). So, you can just create a list of > objects (for example) and bind that: > > List<MyObject> data = new List<MyObject>(); > PopulateData(data); > MyGridView.DataSource = data; > MyGridView.DataBind(); > > MyObject can be any class with public properties. So each object instance > is a "row" and each public property is (potentially) a "column". IMO, it's > even easier than adding rows & columns "manually".
Yeah, I'm actually doing this now. It's definitely easier than adding rows manually, but it doesn't provide as much control over some details. Thanks. -- Jonathan Wood SoftCircuits Programming http://www.softcircuits.com
I haven't tried that, no. But I'll look into it. One problem is that I don't do any processing when the row is selected. But then I have some buttons that are not part of the grid. When they are clicked, then I need to be able to locate the ID of the selected item. Thanks. -- Jonathan Wood SoftCircuits Programming http://www.softcircuits.com [quoted text, click to view] "Hosmerica" <BigOneComing@IveGotGas.com> wrote in message news:KPidnYejUquTzQXanZ2dnUVZ_rqlnZ2d@comcast.com... > > "Jonathan Wood" <jwood@softcircuits.com> wrote in message > news:eXe3ZlkXIHA.3940@TK2MSFTNGP05.phx.gbl... >> I'm displaying data in a GridView that allows user to select a row. When >> a button is clicked, I need to locate the selected row. >> >> The problem is that I need an ID value from the selected row, but I do >> not want to display that ID value in the grid. I tried creating a hidden >> column, but I can't seem to be able to access it when the button is >> clicked. (At least, hidden columns do not appear to show up in the Cells >> collection of the selected row.) > > Have you tried using CommandArgument and/or CommandName? The > CommandArgument can be assigned to the button as can the CommandName. > When you click the button, you'd have to catch it in the RowCommand Event. > You can do your processing from there. >
Mark, [quoted text, click to view] > When the data is bound to the GridView, populate the button's > CommandArgument property with the ID... > > However, there's no need to use a button if all you want is the user to be > able to select a row: > > protected void MyGridView_RowDataBound(object sender, GridViewRowEventArgs > e) > { > if (e.Row.RowType == DataControlRowType.DataRow) > { > e.Row.Style["cursor"] = "pointer"; > e.Row.Attributes.Add("onclick", > ClientScript.GetPostBackEventReference(MyGridView, "Select$" + > e.Row.RowIndex.ToString())); > } > } > > protected void MyGridView_SelectedIndexChanged(object sender, EventArgs e) > { > Response.Redirect("OtherPage.aspx?ID=" + > MyGridView.SelectedValue.ToString(), false); > }
Yeah, I'll play around with that. But, like I mentioned elsewhere in this thread, I don't do any processing when the item is selected. I need to be able to access the ID of the selected row when a button outside the grid is pressed. It sounds like this is mostly geared towards handling row events--unless there's a bit more to this. Thanks. -- Jonathan Wood SoftCircuits Programming http://www.softcircuits.com
Jonathan, No need to write custom code (like setting commandargument) as GridView has a built in mechanism of handling such scenario, already mentioned by Scott. In addition you can use currently selected ID wherever you like: <asp:GridView runat="server" ID="gv" DataKeyNames="IDFieldOrIDColumn" AutoGenerateColumns="false"> <Columns> <asp:BoundField DataField="WhateEver" /> </Columns> </asp:GridView> in the code you can simply write: if (gv.SelectedValue != null) { // i assume record id is integer int recordId = (int) gv.SelectedValue; } No need for writing custom code -- Milosz [quoted text, click to view] "Jonathan Wood" wrote: > I'm displaying data in a GridView that allows user to select a row. When a > button is clicked, I need to locate the selected row. > > The problem is that I need an ID value from the selected row, but I do not > want to display that ID value in the grid. I tried creating a hidden column, > but I can't seem to be able to access it when the button is clicked. (At > least, hidden columns do not appear to show up in the Cells collection of > the selected row.) > > Is there any way to get an ID for the selected row without displaying that > ID to the user? > > Also, does anyone know if there's any way to populate a GridView control > without using the DataSource property, by just programatically adding rows > to the grid? > > Thanks. > > -- > Jonathan Wood > SoftCircuits Programming > http://www.softcircuits.com >
[quoted text, click to view] >> MyObject can be any class with public properties. So each object instance >> is a "row" and each public property is (potentially) a "column". IMO, >> it's even easier than adding rows & columns "manually". > > Yeah, I'm actually doing this now. It's definitely easier than adding rows > manually, but it doesn't provide as much control over some details.
Purely out of curiosity - what details?
Scott, [quoted text, click to view] >>> MyObject can be any class with public properties. So each object >>> instance >>> is a "row" and each public property is (potentially) a "column". IMO, >>> it's even easier than adding rows & columns "manually". >> >> Yeah, I'm actually doing this now. It's definitely easier than adding >> rows manually, but it doesn't provide as much control over some details. > > Purely out of curiosity - what details?
Well, I'm still working that out. <g> Some things I'm looking at including only showing the value in one column when it is different from the last. Also, I'd like to alternate row colors based on when this same value changes. I'm not 100% certain if there's anything else I need. -- Jonathan Wood SoftCircuits Programming http://www.softcircuits.com
Assuming you meant gv.SelectedDataKey.Value (instead of gv.SelectedValue) then, yeah, that should do what I want. Thanks. -- Jonathan Wood SoftCircuits Programming http://www.softcircuits.com [quoted text, click to view] "Milosz Skalecki [MCAD]" <mily242@DONTLIKESPAMwp.pl> wrote in message news:BCF0162D-6475-426C-964A-8FE8C0B09C53@microsoft.com... > Jonathan, > > No need to write custom code (like setting commandargument) as GridView > has > a built in mechanism of handling such scenario, already mentioned by > Scott. > In addition you can use currently selected ID wherever you like: > > <asp:GridView runat="server" ID="gv" DataKeyNames="IDFieldOrIDColumn" > AutoGenerateColumns="false"> > <Columns> > <asp:BoundField DataField="WhateEver" /> > </Columns> > </asp:GridView> > > in the code you can simply write: > > if (gv.SelectedValue != null) > { > // i assume record id is integer > int recordId = (int) gv.SelectedValue; > } > > No need for writing custom code > -- > Milosz > > > "Jonathan Wood" wrote: > >> I'm displaying data in a GridView that allows user to select a row. When >> a >> button is clicked, I need to locate the selected row. >> >> The problem is that I need an ID value from the selected row, but I do >> not >> want to display that ID value in the grid. I tried creating a hidden >> column, >> but I can't seem to be able to access it when the button is clicked. (At >> least, hidden columns do not appear to show up in the Cells collection of >> the selected row.) >> >> Is there any way to get an ID for the selected row without displaying >> that >> ID to the user? >> >> Also, does anyone know if there's any way to populate a GridView control >> without using the DataSource property, by just programatically adding >> rows >> to the grid? >> >> Thanks. >> >> -- >> Jonathan Wood >> SoftCircuits Programming >> http://www.softcircuits.com >> >>
Er... no, I guess you did mean SelectedValue. Although, I'm not clear on the difference between SelectedDataKey.Value and SelectedValue. Are they the same thing? -- Jonathan Wood SoftCircuits Programming http://www.softcircuits.com [quoted text, click to view] "Milosz Skalecki [MCAD]" <mily242@DONTLIKESPAMwp.pl> wrote in message news:BCF0162D-6475-426C-964A-8FE8C0B09C53@microsoft.com... > Jonathan, > > No need to write custom code (like setting commandargument) as GridView > has > a built in mechanism of handling such scenario, already mentioned by > Scott. > In addition you can use currently selected ID wherever you like: > > <asp:GridView runat="server" ID="gv" DataKeyNames="IDFieldOrIDColumn" > AutoGenerateColumns="false"> > <Columns> > <asp:BoundField DataField="WhateEver" /> > </Columns> > </asp:GridView> > > in the code you can simply write: > > if (gv.SelectedValue != null) > { > // i assume record id is integer > int recordId = (int) gv.SelectedValue; > } > > No need for writing custom code > -- > Milosz > > > "Jonathan Wood" wrote: > >> I'm displaying data in a GridView that allows user to select a row. When >> a >> button is clicked, I need to locate the selected row. >> >> The problem is that I need an ID value from the selected row, but I do >> not >> want to display that ID value in the grid. I tried creating a hidden >> column, >> but I can't seem to be able to access it when the button is clicked. (At >> least, hidden columns do not appear to show up in the Cells collection of >> the selected row.) >> >> Is there any way to get an ID for the selected row without displaying >> that >> ID to the user? >> >> Also, does anyone know if there's any way to populate a GridView control >> without using the DataSource property, by just programatically adding >> rows >> to the grid? >> >> Thanks. >> >> -- >> Jonathan Wood >> SoftCircuits Programming >> http://www.softcircuits.com >> >>
I'll have to take your word for it. I can't seem to see how CommandArgument could be made to work for my purposes. -- Jonathan Wood SoftCircuits Programming http://www.softcircuits.com [quoted text, click to view] "Mark Rae [MVP]" <mark@markNOSPAMrae.net> wrote in message news:%23b8nycrXIHA.1132@TK2MSFTNGP06.phx.gbl... > "Jonathan Wood" <jwood@softcircuits.com> wrote in message > news:%23lyidCrXIHA.4880@TK2MSFTNGP03.phx.gbl... > >> Yeah, I'll play around with that. But, like I mentioned elsewhere in this >> thread, I don't do any processing when the item is selected. I need to be >> able to access the ID of the selected row when a button outside the grid >> is pressed. > > In that case, the CommandArgument property is definitely the way to go... > > > -- > Mark Rae > ASP.NET MVP > http://www.markrae.net
Hi Jonathan, SelectedValue is a shortcut for SelectedDataKey.Value which is a wrapper around DataKeyArray[SelectedIndex] and SelectedDataKey.Values[0]. It matters only if you use several columns in DataKeyNames (which i don't think is the case now?). Regards, -- Milosz [quoted text, click to view] "Jonathan Wood" wrote: > Er... no, I guess you did mean SelectedValue. Although, I'm not clear on the > difference between SelectedDataKey.Value and SelectedValue. Are they the > same thing? > -- > Jonathan Wood > SoftCircuits Programming > http://www.softcircuits.com > > "Milosz Skalecki [MCAD]" <mily242@DONTLIKESPAMwp.pl> wrote in message > news:BCF0162D-6475-426C-964A-8FE8C0B09C53@microsoft.com... > > Jonathan, > > > > No need to write custom code (like setting commandargument) as GridView > > has > > a built in mechanism of handling such scenario, already mentioned by > > Scott. > > In addition you can use currently selected ID wherever you like: > > > > <asp:GridView runat="server" ID="gv" DataKeyNames="IDFieldOrIDColumn" > > AutoGenerateColumns="false"> > > <Columns> > > <asp:BoundField DataField="WhateEver" /> > > </Columns> > > </asp:GridView> > > > > in the code you can simply write: > > > > if (gv.SelectedValue != null) > > { > > // i assume record id is integer > > int recordId = (int) gv.SelectedValue; > > } > > > > No need for writing custom code > > -- > > Milosz > > > > > > "Jonathan Wood" wrote: > > > >> I'm displaying data in a GridView that allows user to select a row. When > >> a > >> button is clicked, I need to locate the selected row. > >> > >> The problem is that I need an ID value from the selected row, but I do > >> not > >> want to display that ID value in the grid. I tried creating a hidden > >> column, > >> but I can't seem to be able to access it when the button is clicked. (At > >> least, hidden columns do not appear to show up in the Cells collection of > >> the selected row.) > >> > >> Is there any way to get an ID for the selected row without displaying > >> that > >> ID to the user? > >> > >> Also, does anyone know if there's any way to populate a GridView control > >> without using the DataSource property, by just programatically adding > >> rows > >> to the grid? > >> > >> Thanks. > >> > >> -- > >> Jonathan Wood > >> SoftCircuits Programming > >> http://www.softcircuits.com > >> > >> >
Right, I suspected they might be the same things. Thanks. -- Jonathan Wood SoftCircuits Programming http://www.softcircuits.com [quoted text, click to view] "Milosz Skalecki [MCAD]" <mily242@DONTLIKESPAMwp.pl> wrote in message news:D18B28EA-E77C-4337-AC9D-B413DD0A2315@microsoft.com... > Hi Jonathan, > > SelectedValue is a shortcut for SelectedDataKey.Value which is a wrapper > around > DataKeyArray[SelectedIndex] and SelectedDataKey.Values[0]. It matters only > if you use several columns in DataKeyNames (which i don't think is the > case > now?). > > Regards, > -- > Milosz > > > "Jonathan Wood" wrote: > >> Er... no, I guess you did mean SelectedValue. Although, I'm not clear on >> the >> difference between SelectedDataKey.Value and SelectedValue. Are they the >> same thing? >> -- >> Jonathan Wood >> SoftCircuits Programming >> http://www.softcircuits.com >> >> "Milosz Skalecki [MCAD]" <mily242@DONTLIKESPAMwp.pl> wrote in message >> news:BCF0162D-6475-426C-964A-8FE8C0B09C53@microsoft.com... >> > Jonathan, >> > >> > No need to write custom code (like setting commandargument) as GridView >> > has >> > a built in mechanism of handling such scenario, already mentioned by >> > Scott. >> > In addition you can use currently selected ID wherever you like: >> > >> > <asp:GridView runat="server" ID="gv" DataKeyNames="IDFieldOrIDColumn" >> > AutoGenerateColumns="false"> >> > <Columns> >> > <asp:BoundField DataField="WhateEver" /> >> > </Columns> >> > </asp:GridView> >> > >> > in the code you can simply write: >> > >> > if (gv.SelectedValue != null) >> > { >> > // i assume record id is integer >> > int recordId = (int) gv.SelectedValue; >> > } >> > >> > No need for writing custom code >> > -- >> > Milosz >> > >> > >> > "Jonathan Wood" wrote: >> > >> >> I'm displaying data in a GridView that allows user to select a row. >> >> When >> >> a >> >> button is clicked, I need to locate the selected row. >> >> >> >> The problem is that I need an ID value from the selected row, but I do >> >> not >> >> want to display that ID value in the grid. I tried creating a hidden >> >> column, >> >> but I can't seem to be able to access it when the button is clicked. >> >> (At >> >> least, hidden columns do not appear to show up in the Cells collection >> >> of >> >> the selected row.) >> >> >> >> Is there any way to get an ID for the selected row without displaying >> >> that >> >> ID to the user? >> >> >> >> Also, does anyone know if there's any way to populate a GridView >> >> control >> >> without using the DataSource property, by just programatically adding >> >> rows >> >> to the grid? >> >> >> >> Thanks. >> >> >> >> -- >> >> Jonathan Wood >> >> SoftCircuits Programming >> >> http://www.softcircuits.com >> >> >> >> >> >>
Hi there again, Sorry i wasn't clear. In most scenarios, you need just one column to identify the row (i.e. UserId - usually identity column automatically incremented). Now, in order to simplify the code, it's easier to use just gridView.SelectedValue than gridView.SelectedDataKey.Values[0]. But sometimes one column is not enough, or you want to store more values from the record per each row, i.e. you want UserId, Login, LastLoginDate information to be available for each record: int userId = (int) gridView.SelectedDataKey.Values[0]; string login = (string) gridView.SelectedDataKey.Values[1]; DateTime lastLoginDate = (DateTime) gridView.SelectedDataKey.Values[2]; Hope it's clear now :) Regards -- Milosz [quoted text, click to view] "Jonathan Wood" wrote: > Right, I suspected they might be the same things. > > Thanks. > > -- > Jonathan Wood > SoftCircuits Programming > http://www.softcircuits.com > > "Milosz Skalecki [MCAD]" <mily242@DONTLIKESPAMwp.pl> wrote in message > news:D18B28EA-E77C-4337-AC9D-B413DD0A2315@microsoft.com... > > Hi Jonathan, > > > > SelectedValue is a shortcut for SelectedDataKey.Value which is a wrapper > > around > > DataKeyArray[SelectedIndex] and SelectedDataKey.Values[0]. It matters only > > if you use several columns in DataKeyNames (which i don't think is the > > case > > now?). > > > > Regards, > > -- > > Milosz > > > > > > "Jonathan Wood" wrote: > > > >> Er... no, I guess you did mean SelectedValue. Although, I'm not clear on > >> the > >> difference between SelectedDataKey.Value and SelectedValue. Are they the > >> same thing? > >> -- > >> Jonathan Wood > >> SoftCircuits Programming > >> http://www.softcircuits.com > >> > >> "Milosz Skalecki [MCAD]" <mily242@DONTLIKESPAMwp.pl> wrote in message > >> news:BCF0162D-6475-426C-964A-8FE8C0B09C53@microsoft.com... > >> > Jonathan, > >> > > >> > No need to write custom code (like setting commandargument) as GridView > >> > has > >> > a built in mechanism of handling such scenario, already mentioned by > >> > Scott. > >> > In addition you can use currently selected ID wherever you like: > >> > > >> > <asp:GridView runat="server" ID="gv" DataKeyNames="IDFieldOrIDColumn" > >> > AutoGenerateColumns="false"> > >> > <Columns> > >> > <asp:BoundField DataField="WhateEver" /> > >> > </Columns> > >> > </asp:GridView> > >> > > >> > in the code you can simply write: > >> > > >> > if (gv.SelectedValue != null) > >> > { > >> > // i assume record id is integer > >> > int recordId = (int) gv.SelectedValue; > >> > } > >> > > >> > No need for writing custom code > >> > -- > >> > Milosz > >> > > >> > > >> > "Jonathan Wood" wrote: > >> > > >> >> I'm displaying data in a GridView that allows user to select a row. > >> >> When > >> >> a > >> >> button is clicked, I need to locate the selected row. > >> >> > >> >> The problem is that I need an ID value from the selected row, but I do > >> >> not > >> >> want to display that ID value in the grid. I tried creating a hidden > >> >> column, > >> >> but I can't seem to be able to access it when the button is clicked. > >> >> (At > >> >> least, hidden columns do not appear to show up in the Cells collection > >> >> of > >> >> the selected row.) > >> >> > >> >> Is there any way to get an ID for the selected row without displaying > >> >> that > >> >> ID to the user? > >> >> > >> >> Also, does anyone know if there's any way to populate a GridView > >> >> control > >> >> without using the DataSource property, by just programatically adding > >> >> rows > >> >> to the grid? > >> >> > >> >> Thanks. > >> >> > >> >> -- > >> >> Jonathan Wood > >> >> SoftCircuits Programming > >> >> http://www.softcircuits.com > >> >> > >> >> > >> > >> >
Sorry i wasn't clear. In most scenarios, you need just one column to identify the row (i.e. UserId - usually identity column automatically incremented). Now, in order to simplify the code, it's easier to use just gridView.SelectedValue than gridView.SelectedDataKey.Values[0]. But sometimes one column is not enough, or you want to store more values from the record per each row, i.e. you want UserId, Login, LastLoginDate information to be available for each record: int userId = (int) gridView.SelectedDataKey.Values[0]; string login = (string) gridView.SelectedDataKey.Values[1]; DateTime lastLoginDate = (DateTime) gridView.SelectedDataKey.Values[2]; Hope it's clear now :) Regards -- Milosz [quoted text, click to view] "Jonathan Wood" wrote: > Right, I suspected they might be the same things. > > Thanks. > > -- > Jonathan Wood > SoftCircuits Programming > http://www.softcircuits.com > > "Milosz Skalecki [MCAD]" <mily242@DONTLIKESPAMwp.pl> wrote in message > news:D18B28EA-E77C-4337-AC9D-B413DD0A2315@microsoft.com... > > Hi Jonathan, > > > > SelectedValue is a shortcut for SelectedDataKey.Value which is a wrapper > > around > > DataKeyArray[SelectedIndex] and SelectedDataKey.Values[0]. It matters only > > if you use several columns in DataKeyNames (which i don't think is the > > case > > now?). > > > > Regards, > > -- > > Milosz > > > > > > "Jonathan Wood" wrote: > > > >> Er... no, I guess you did mean SelectedValue. Although, I'm not clear on > >> the > >> difference between SelectedDataKey.Value and SelectedValue. Are they the > >> same thing? > >> -- > >> Jonathan Wood > >> SoftCircuits Programming > >> http://www.softcircuits.com > >> > >> "Milosz Skalecki [MCAD]" <mily242@DONTLIKESPAMwp.pl> wrote in message > >> news:BCF0162D-6475-426C-964A-8FE8C0B09C53@microsoft.com... > >> > Jonathan, > >> > > >> > No need to write custom code (like setting commandargument) as GridView > >> > has > >> > a built in mechanism of handling such scenario, already mentioned by > >> > Scott. > >> > In addition you can use currently selected ID wherever you like: > >> > > >> > <asp:GridView runat="server" ID="gv" DataKeyNames="IDFieldOrIDColumn" > >> > AutoGenerateColumns="false"> > >> > <Columns> > >> > <asp:BoundField DataField="WhateEver" /> > >> > </Columns> > >> > </asp:GridView> > >> > > >> > in the code you can simply write: > >> > > >> > if (gv.SelectedValue != null) > >> > { > >> > // i assume record id is integer > >> > int recordId = (int) gv.SelectedValue; > >> > } > >> > > >> > No need for writing custom code > >> > -- > >> > Milosz > >> > > >> > > >> > "Jonathan Wood" wrote: > >> > > >> >> I'm displaying data in a GridView that allows user to select a row. > >> >> When > >> >> a > >> >> button is clicked, I need to locate the selected row. > >> >> > >> >> The problem is that I need an ID value from the selected row, but I do > >> >> not > >> >> want to display that ID value in the grid. I tried creating a hidden > >> >> column, > >> >> but I can't seem to be able to access it when the button is clicked. > >> >> (At > >> >> least, hidden columns do not appear to show up in the Cells collection > >> >> of > >> >> the selected row.) > >> >> > >> >> Is there any way to get an ID for the selected row without displaying > >> >> that > >> >> ID to the user? > >> >> > >> >> Also, does anyone know if there's any way to populate a GridView > >> >> control > >> >> without using the DataSource property, by just programatically adding > >> >> rows > >> >> to the grid? > >> >> > >> >> Thanks. > >> >> > >> >> -- > >> >> Jonathan Wood > >> >> SoftCircuits Programming > >> >> http://www.softcircuits.com > >> >> > >> >> > >> > >> >
[quoted text, click to view] "Jonathan Wood" <jwood@softcircuits.com> wrote in message news:%23lyidCrXIHA.4880@TK2MSFTNGP03.phx.gbl... > Yeah, I'll play around with that. But, like I mentioned elsewhere in this > thread, I don't do any processing when the item is selected. I need to be > able to access the ID of the selected row when a button outside the grid > is pressed.
In that case, the CommandArgument property is definitely the way to go... -- Mark Rae ASP.NET MVP http://www.markrae.net
Don't see what you're looking for? Try a search.
|
|
|