Click here to Skip to main content
15,884,083 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
<tr>
       <td align="left" class="label" style="height: 23px" valign="top">
           <asp:Label ID="lbl_Scale_pointers" runat="server" Text="Scale pointers"></asp:Label></td>
       <td align="left" class="label" style="width: 1px; height: 23px;" valign="top">
           :</td>
       <td align="left" class="control" style="height: 23px">
           <%--<cc1:DropDownListControl ID="ddlst_Scale_pointers" runat="server">
           </cc1:DropDownListControl>--%>
           <asp:DropDownList ID="ddlst_Scale_pointers" runat="server" AutoPostBack="True" Width="80px">
           <asp:ListItem>1</asp:ListItem>
           <asp:ListItem>2</asp:ListItem>
           <asp:ListItem>3</asp:ListItem>
           <asp:ListItem>4</asp:ListItem>
           <asp:ListItem>5</asp:ListItem>
           <asp:ListItem>6</asp:ListItem>
           <asp:ListItem>7</asp:ListItem>

           </asp:DropDownList>
       </td>
   </tr>
   <tr>
   <td align ="center" class="label" style="height: 23px" valign="top">
   <asp:Label ID="lblcolor" runat="server" Text="Please pick the color for Pointer"></asp:Label>
   </td>
   </tr>

   <tr>
  <%--<td align="center" class="label" style="height: 23px" valign="top">
         <asp:Label Visible="false" ID="Label1" runat="server" Text=""></asp:Label></td>

       <td align="center"  class="label" style="width: 1px; height: 23px;" valign="top">
           </td>--%>
  <td align="center" colspan="3"  class="control" style="height: 23px" valign="top"  >

  <asp:GridView  ID="grdvw1" EnableViewState="true" OnRowDataBound="grdvw1_RowDataBound" runat="server" Width="300px" CellSpacing="3" CellPadding ="3">


   <Columns>
           <asp:TemplateField HeaderText="Pointer No">
           <ItemTemplate>
           <asp:Label Text="" ID="lblPointerNo" runat="server" >
           </asp:Label>
           </ItemTemplate>
           </asp:TemplateField>
   </Columns>

   <Columns>
           <asp:TemplateField HeaderText="Pointer Color">
           <ItemTemplate>
           <asp:TextBox ID="txtcolor" runat="server" class="color" MaxLength="19" Width="200px"></asp:TextBox>
           </ItemTemplate>
           </asp:TemplateField>
   </Columns>

    </asp:GridView>

   </td>

   </tr>


VB
Protected Sub ddlst_Scale_pointers_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlst_Scale_pointers.SelectedIndexChanged
       BindGridview(ddlst_Scale_pointers.SelectedValue)
   End Sub
Sub BindGridview(ByVal rownum As Integer)
For i As Integer = 0 To rownum - 1   

    Dim lblTest As Label = CType(grdvw1.FindControl("lblPointerNo"), Label)
    lblTest.Text = i + 1 
    
Next

grdvw1.DataBind()
End sub

on selection of dropdownlist value i need number of rows for grid

I want to change the value of label dynamically that is if dropdwnlist has value 3 then the lblpionter no should display
1
2
3 in 3 diff rows so do any1 has the ans for this
Posted
Updated 12-Feb-13 6:52am
v6
Comments
PrachiMhatre 12-Feb-13 7:27am    
Please clarify the requirement..
ZurdoDev 12-Feb-13 11:04am    
Where are you stuck?
Karthik Harve 12-Feb-13 12:50pm    
[Edit] pre tags added

1 solution

Hi,

change the gridview source as below.
ASP.NET
<columns>
    <asp:templatefield headertext="Pointer No" xmlns:asp="#unknown">
    <itemtemplate>
    <asp:label text='<%#Eval("PointerNo")%>' id="lblPointerNo" runat="server">
    </asp:label>
    </itemtemplate>
    </asp:templatefield>
</columns>

bind the gidview as below.
VB
Sub BindGridview(ByVal rownum As Integer)
Dim dt as New DataTable
dt.Columns.Add("PointerNo", Type.GetType(string))
dt.AcceptChanges()

For i As Integer = 0 To rownum - 1   
 dt.Rows.Add((i + 1).ToString())
 dt.AcceptChanges()
Next
 
grdvw1.DataSource = dt
grdvw1.DataBind()
End sub


option Two

keep the grid view source unchanged. add the below code in RowDataBoundEvent.

VB
Dim lbl as Label = CType(e.Row.FindControl("lblPointerNo"), Label)
If lbl IsNot  Nothing THEN
    IF e.Row.RowIndex < Convert.ToInt32(ddlst_Scale_pointers.SelectedValue) THEN
        lbl.Text = (e.Row.RowIndex + 1).ToString();
    End If
End If


hope it helps
 
Share this answer
 
v4
Comments
Member 9410081 13-Feb-13 1:28am    
I am not able to get the values in label
Karthik Harve 13-Feb-13 1:31am    
did you added the Eval function in gridview source ?
Member 9410081 13-Feb-13 1:40am    
NO
Member 9410081 13-Feb-13 1:41am    
ya i have added
Karthik Harve 13-Feb-13 3:31am    
what is the error message ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900