Get values from selected item in listview using asp.net c# -
i've tried many many different ways of displaying values listview either textbox or store in session , use later, none of works.
i able make work gridview, can't make work listview.
the idea id of selected user (in gridview) , id of selected club (in listview)
after getting , storing both id's selected rows, can add club user.
let's have table clubs has item: (4 columns, 1 row)
id: 1 clubname: los angeles lakers city: los angeles state: california
when press on first row, should highlight in different color, , store id either session or textbox. doesn't matter i'll decide later. can guys please me id ?
this source code
<asp:listview id="listview1" runat="server" datakeynames="klubid" datasourceid="sqldatasource1" onselectedindexchanged="listview1_selectedindexchanged" style="margin-right: 324px" onrowcreated="gridview1_rowcreated"> <alternatingitemtemplate> <tr style="background-color:#fff8dc;"> <td> <asp:label id="klubidlabel" runat="server" text='<%# eval("klubid") %>' /> </td> <td> <asp:label id="imeklubalabel" runat="server" text='<%# eval("imekluba") %>' /> </td> <td> <asp:label id="krajlabel" runat="server" text='<%# eval("kraj") %>' /> </td> <td> <asp:label id="drzavalabel" runat="server" text='<%# eval("drzava") %>' /> </td> <td> <asp:label id="menedzerlabel" runat="server" text='<%# eval("menedzer") %>' /> </td> </tr> </alternatingitemtemplate> <edititemtemplate> <tr style="background-color:#008a8c;color: #ffffff;"> <td> <asp:button id="updatebutton" runat="server" commandname="update" text="update" /> <asp:button id="cancelbutton" runat="server" commandname="cancel" text="cancel" /> </td> <td> <asp:label id="klubidlabel1" runat="server" text='<%# eval("klubid") %>' /> </td> <td> <asp:textbox id="imeklubatextbox" runat="server" text='<%# bind("imekluba") %>' /> </td> <td> <asp:textbox id="krajtextbox" runat="server" text='<%# bind("kraj") %>' /> </td> <td> <asp:textbox id="drzavatextbox" runat="server" text='<%# bind("drzava") %>' /> </td> <td> <asp:textbox id="menedzertextbox" runat="server" text='<%# bind("menedzer") %>' /> </td> </tr> </edititemtemplate> <emptydatatemplate> <table runat="server" style="background-color: #ffffff;border-collapse: collapse;border-color: #999999;border-style:none;border-width:1px;"> <tr> <td>no data returned.</td> </tr> </table> </emptydatatemplate> <insertitemtemplate> <tr style=""> <td> <asp:button id="insertbutton" runat="server" commandname="insert" text="insert" /> <asp:button id="cancelbutton" runat="server" commandname="cancel" text="clear" /> </td> <td> </td> <td> <asp:textbox id="imeklubatextbox" runat="server" text='<%# bind("imekluba") %>' /> </td> <td> <asp:textbox id="krajtextbox" runat="server" text='<%# bind("kraj") %>' /> </td> <td> <asp:textbox id="drzavatextbox" runat="server" text='<%# bind("drzava") %>' /> </td> <td> <asp:textbox id="menedzertextbox" runat="server" text='<%# bind("menedzer") %>' /> </td> </tr> </insertitemtemplate> <itemtemplate> <tr style="background-color:#dcdcdc;color: #000000;"> <td> <asp:label id="klubidlabel" runat="server" text='<%# eval("klubid") %>' /> </td> <td> <asp:label id="imeklubalabel" runat="server" text='<%# eval("imekluba") %>' /> </td> <td> <asp:label id="krajlabel" runat="server" text='<%# eval("kraj") %>' /> </td> <td> <asp:label id="drzavalabel" runat="server" text='<%# eval("drzava") %>' /> </td> <td> <asp:label id="menedzerlabel" runat="server" text='<%# eval("menedzer") %>' /> </td> </tr> </itemtemplate> <layouttemplate> <table runat="server"> <tr runat="server"> <td runat="server"> <table id="itemplaceholdercontainer" runat="server" border="1" style="background-color: #ffffff;border-collapse: collapse;border-color: #999999;border-style:none;border-width:1px;font-family: verdana, arial, helvetica, sans-serif;"> <tr runat="server" style="background-color:#dcdcdc;color: #000000;"> <th runat="server">klubid</th> <th runat="server">imekluba</th> <th runat="server">kraj</th> <th runat="server">drzava</th> <th runat="server">menedzer</th> </tr> <tr id="itemplaceholder" runat="server"> </tr> </table> </td> </tr> <tr runat="server"> <td runat="server" style="text-align: center;background-color: #cccccc;font-family: verdana, arial, helvetica, sans-serif;color: #000000;"> <asp:datapager id="datapager1" runat="server"> <fields> <asp:nextpreviouspagerfield buttontype="button" showfirstpagebutton="true" showlastpagebutton="true" /> </fields> </asp:datapager> </td> </tr> </table> </layouttemplate> <selecteditemtemplate> <tr style="background-color:#008a8c;font-weight: bold;color: #ffffff;"> <td> <asp:label id="klubidlabel" runat="server" text='<%# eval("klubid") %>' /> </td> <td> <asp:label id="imeklubalabel" runat="server" text='<%# eval("imekluba") %>' /> </td> <td> <asp:label id="krajlabel" runat="server" text='<%# eval("kraj") %>' /> </td> <td> <asp:label id="drzavalabel" runat="server" text='<%# eval("drzava") %>' /> </td> <td> <asp:label id="menedzerlabel" runat="server" text='<%# eval("menedzer") %>' /> </td> </tr> </selecteditemtemplate> </asp:listview>
this code - latest, doesnt work
protected void gridview1_rowcreated(object sender, system.web.ui.webcontrols.listviewcommandeventargs e) { listviewdataitem item1 = e.item listviewdataitem; int findme = item1.displayindex; var route = (label)item1.findcontrol("id"); textbox1.text = route.text; }
any input appreciated, thank you!
ps, possible have 2 gridview store different data?
i tried before, everytime selected item in 2nd gridview, item 1st gridview getting selected.
no need convert webcontrol ::
listviewitem item = listview1.items[listview1.selectedindex]; label c = (label)item.findcontrol("here type lable id!!"); //then use string result=c.text;// value or text of label ,,
Comments
Post a Comment