单击行未触发时选择行到文本框

时间:2015-01-15 02:57:20

标签: asp.net vb.net gridview

我可以点击行来选择它们但是当我需要它们到文本框时它没有触发我试图在文本框上使用Autopostback但是它不起作用我认为这是因为每个不能使row.cells(0)工作 我写了这样的代码

VB.NET

  Protected Sub OnSelectedIndexChanged(sender As Object, e As EventArgs)
    For Each row As GridViewRow In GridView1.Rows
        If row.RowIndex = GridView1.SelectedIndex Then
            row.BackColor = ColorTranslator.FromHtml("#E294FF")
            txtrepname.Text = row.Cells(0).Text
            row.ToolTip = String.Empty
        Else
            row.BackColor = ColorTranslator.FromHtml("#FFFFFF")
            row.ToolTip = "Click to select this row."
        End If
    Next
End Sub

Gridview

 <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
    DataSourceID="SqlDataSource1" ShowFooter="True" Width="1280px"    OnRowDataBound = "OnRowDataBound" OnSelectedIndexChanged = "OnSelectedIndexChanged"
    onrowupdating="GridView1_RowUpdating" DataKeyNames="REP_NAME" PageSize="9999">

    <Columns>
        <asp:TemplateField HeaderText="" >        

            <ItemTemplate>
                <asp:LinkButton ID="lnkEdit" runat="server" Text="" CommandName="Edit" ToolTip="Edit"
                CommandArgument=''><img src="Images/ad_edit.png" BORDER="0" /></asp:LinkButton> 
                <asp:LinkButton ID="lnkDelete" runat="server" Text="Delete" CommandName="Delete" 
                ToolTip="Delete" OnClientClick='return confirm("Are you sure you want to delete this entry?");'
                CommandArgument='' BorderColor="#CC3300"><img src="Images/ad_delete.png" BORDER="0" /></asp:LinkButton>    
            </ItemTemplate>
            <EditItemTemplate>                                    
                <asp:LinkButton ID="lnkInsert" runat="server" Text="" ValidationGroup="editGrp" CommandName="Update" ToolTip="Save"
                CommandArgument=''><img src="Images/ad_save.png" BORDER="0" /></asp:LinkButton>
                <asp:LinkButton ID="lnkCancel" runat="server" Text="" CommandName="Cancel" ToolTip="Cancel"
                CommandArgument=''><img src="Images/ad_reload.png" BORDER="0" /></asp:LinkButton>
            </EditItemTemplate>
            <FooterTemplate>                                    
                <asp:LinkButton ID="lnkInsert" runat="server" Text=""  ValidationGroup="newGrp" CommandName="InsertNew" ToolTip="Add New Entry"
                CommandArgument=''><img src="Images/ad_add.png" BORDER="0"/></asp:LinkButton>
                <asp:LinkButton ID="lnkCancel" runat="server" Text="" CommandName="CancelNew" ToolTip="Cancel"
                CommandArgument=''><img src="Images/ad_reload.png"  BORDER="0"/></asp:LinkButton>
            </FooterTemplate>
            <HeaderStyle Width="60px" />
        </asp:TemplateField> 
        <asp:TemplateField HeaderText="Report Name" SortExpression="REP_NAME" >
            <ItemTemplate>
                <div style="overflow:hidden; text-overflow:ellipsis; white-space:nowrap; min-width:150px; ">
                <asp:Label ID="Label1" runat="server" Text='<%# Bind("REP_NAME") %>'></asp:Label>
                </div>
            </ItemTemplate>
            <EditItemTemplate>
                <asp:Label ID="Label1" runat="server" Text='<%# Eval("REP_NAME") %>'></asp:Label>
            </EditItemTemplate>
            <FooterTemplate>
                <asp:TextBox ID="txtREP_NAMENew" runat="server" CssClass="" Width="60px"   ></asp:TextBox>
                <asp:RequiredFieldValidator ID="valREP_FILEID" runat="server" ControlToValidate="txtREP_NAMENew"
                Display="Dynamic" ErrorMessage="Province is required." ForeColor="Red" SetFocusOnError="True"
                ValidationGroup="newGrp">*</asp:RequiredFieldValidator>
            </FooterTemplate>
            <HeaderStyle Width="80px" />
        </asp:TemplateField>

    </Columns>
</asp:GridView>

0 个答案:

没有答案