title: ASP.NET and ListView control having LinkButton
body: <p>I have 10 questions in my sql database. I get them and print them in Link form using LinkButton.  Now i want to generate click event of every question separately.    </p>
  
  <p>How to generate OnClick event of LinkButton inside ListView. Please help in easy steps.</p>
  
  <pre><code>  &lt;asp:ListView ID="ListView1" runat="server" DataSourceID="SqlDataSource1" DataKeyNames="userid" &gt;
                      &lt;AlternatingItemTemplate&gt;
                          &lt;tr style=""&gt;
                              &lt;td&gt;
                                 &lt;%-- &lt;asp:Label ID="qtLabel" runat="server" Text='&lt;%# Eval("qt") %&gt;' /&gt;
                         --%&gt;
                                   &lt;h3&gt; &lt;asp:LinkButton CommandArgument='&lt;%# Eval("userid") %&gt;' ID="LinkButton1" runat="server"&gt;&lt;%# Eval("qt") %&gt;&lt;/asp:LinkButton&gt;  &lt;/h3&gt;
  
                              &lt;/td&gt;
                              &lt;td&gt;
                                  &lt;asp:Label ID="useridLabel" runat="server" Text='&lt;%# Eval("userid") %&gt;' /&gt;
                              &lt;/td&gt;
                          &lt;/tr&gt;
                      &lt;/AlternatingItemTemplate&gt;
                      &lt;EditItemTemplate&gt;
                          &lt;tr style=""&gt;
                              &lt;td&gt;
                                  &lt;asp:Button ID="UpdateButton" runat="server" CommandName="Update" Text="Update" /&gt;
                                  &lt;asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Cancel" /&gt;
                              &lt;/td&gt;
                              &lt;td&gt;
                                  &lt;asp:TextBox ID="qtTextBox" runat="server" Text='&lt;%# Bind("qt") %&gt;' /&gt;
                              &lt;/td&gt;
                              &lt;td&gt;
                                  &lt;asp:Label ID="useridLabel1" runat="server" Text='&lt;%# Eval("userid") %&gt;' /&gt;
                              &lt;/td&gt;
                          &lt;/tr&gt;
                      &lt;/EditItemTemplate&gt;
                      &lt;EmptyDataTemplate&gt;
                          &lt;table runat="server" style=""&gt;
                              &lt;tr&gt;
                                  &lt;td&gt;No data was returned.&lt;/td&gt;
                              &lt;/tr&gt;
                          &lt;/table&gt;
                      &lt;/EmptyDataTemplate&gt;
                      &lt;InsertItemTemplate&gt;
                          &lt;tr style=""&gt;
                              &lt;td&gt;
                                  &lt;asp:Button ID="InsertButton" runat="server" CommandName="Insert" Text="Insert" /&gt;
                                  &lt;asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Clear" /&gt;
                              &lt;/td&gt;
                              &lt;td&gt;
                                  &lt;asp:TextBox ID="qtTextBox" runat="server" Text='&lt;%# Bind("qt") %&gt;' /&gt;
                              &lt;/td&gt;
                              &lt;td&gt;
                                  &lt;asp:TextBox ID="useridTextBox" runat="server" Text='&lt;%# Bind("userid") %&gt;' /&gt;
                              &lt;/td&gt;
                          &lt;/tr&gt;
                      &lt;/InsertItemTemplate&gt;
                      &lt;ItemTemplate&gt;
                          &lt;tr style=""&gt;
                              &lt;td&gt;
                                 &lt;h3&gt; &lt;asp:LinkButton ID="LinkButton1" CommandArgument='&lt;%# Eval("userid") %&gt;' runat="server"&gt;&lt;%# Eval("qt") %&gt;&lt;/asp:LinkButton&gt;  &lt;/h3&gt;
                              &lt;/td&gt;
                              &lt;td&gt;
                                  &lt;asp:Label ID="useridLabel" runat="server" Text='&lt;%# Eval("userid") %&gt;' /&gt;
                              &lt;/td&gt;
                          &lt;/tr&gt;
                      &lt;/ItemTemplate&gt;
                      &lt;LayoutTemplate&gt;
                          &lt;table runat="server"&gt;
                              &lt;tr runat="server"&gt;
                                  &lt;td runat="server"&gt;
                                      &lt;table id="itemPlaceholderContainer" runat="server" border="0" style=""&gt;
                                          &lt;tr runat="server" style=""&gt;
                                              &lt;th runat="server"&gt;qt&lt;/th&gt;
                                              &lt;th runat="server"&gt;userid&lt;/th&gt;
                                          &lt;/tr&gt;
                                          &lt;tr id="itemPlaceholder" runat="server"&gt;
                                          &lt;/tr&gt;
                                      &lt;/table&gt;
                                  &lt;/td&gt;
                              &lt;/tr&gt;
                              &lt;tr runat="server"&gt;
                                  &lt;td runat="server" style=""&gt;&lt;/td&gt;
                              &lt;/tr&gt;
                          &lt;/table&gt;
                      &lt;/LayoutTemplate&gt;
                      &lt;SelectedItemTemplate&gt;
                          &lt;tr style=""&gt;
                              &lt;td&gt;
                                  &lt;asp:Label ID="qtLabel" runat="server" Text='&lt;%# Eval("qt") %&gt;' /&gt;
  
                              &lt;/td&gt;
                              &lt;td&gt;
                                  &lt;asp:Label ID="useridLabel" runat="server" Text='&lt;%# Eval("userid") %&gt;' /&gt;
                              &lt;/td&gt;
                          &lt;/tr&gt;
                      &lt;/SelectedItemTemplate&gt;
                  &lt;/asp:ListView&gt;
                  &lt;asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="&lt;%$ ConnectionStrings:DatabaseConnectionString %&gt;" SelectCommand="SELECT [qt], [userid] FROM [java]"&gt;&lt;/asp:SqlDataSource&gt;
  </code></pre>