I have gridview with checkbox, boundfield and textboxfor input data. Also using quicksearch.js in gridheader. When i select some filtered data rowindex value is not correct and the update gone wrong data.
The form work well before i implemented quick search. I am quite new in js, and now the rowindex is not good (value form txtUP is ok), but the rowindex is not ok.
My update button is outside gridview.
<script type="text/javascript" src="Scripts/quicksearch.js"></script>
<script type="text/javascript">
$(function () {
$('.search_textbox').each(function (i) {
$(this).quicksearch("[id*=GridTrx] tr:not(:has(th))", {
'testQuery': function (query, txt, row) {
return $(row).children(":eq(" + i + ")").text().toLowerCase().indexOf(query[0].toLowerCase()) != -1;
}
});
});
});
</script>
<asp:GridView ID="GridTrx" runat="server" AutoGenerateColumns="False" Width="1050px"
OnDataBound="OnDataBound" AllowSorting="True" OnSorting="GridTrx_Sorting" ClientIDMode="Static">
<Columns>
<asp:TemplateField HeaderText="" ItemStyle-HorizontalAlign="Left">
<HeaderTemplate>
<asp:CheckBox ID="chkHeader" runat="server" onclick="checkAll(this);" Visible="false" />
</HeaderTemplate>
<HeaderStyle Height="50px" />
<ItemTemplate>
<asp:CheckBox ID="chkRow" runat="server" onclick="Check_Click(this)" />
</ItemTemplate>
<ItemStyle Width="50px" />
</asp:TemplateField>
<asp:BoundField DataField="name" HeaderText="Current UP name" SortExpression="name"
HtmlEncode="false">
<ItemStyle Font-Names="Arial" Font-Size="X-Small" Font-Bold="True" />
</asp:BoundField>
<asp:TemplateField HeaderText="New UP name" SortExpression="name">
<ItemTemplate>
<asp:TextBox ID="txtUP" runat="server" AutoPostBack="false" Text='<%# Bind("name") %>'
Enabled="false" Font-Names="Arail" Font-Size="X-Small" Width="500px">
</asp:TextBox>
</ItemTemplate>
<ItemStyle Font-Names="Arial" Font-Size="X-Small" Width="500px" />
</asp:TemplateField>
<asp:BoundField DataField="broj" HeaderText="broj" SortExpression="broj">
<ItemStyle Font-Names="Arial" Font-Size="X-Small" Font-Bold="True" />
</asp:BoundField>
</Columns>
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle CssClass="pager-row" HorizontalAlign="Center" BackColor="#284775" ForeColor="White" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#999999" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
</asp:GridView>
</div>
<div>
<input id="Hidden1" type="hidden" />
</div>
</div>
<asp:SqlDataSource ID="sqlDatum" runat="server" ConnectionString="<%$ ConnectionStrings:conMA %>"
SelectCommand="select distinct convert(char(10),datumImport,1) as datumImport FROM [M_A_TI_PN].[dbo].[Table_import] a with(nolock) order by 1">
</asp:SqlDataSource>
Protected Sub BtnUpdate_Click(sender As Object, e As EventArgs) Handles BtnUpdate.Click
Dim userUpdate As String = Session("user")
Dim DateUpdate As Date = Now.Date
Dim Name_old As String = String.Empty
Dim Name_new As String = String.Empty
If DdllDatum.SelectedValue = "%" Then
ClientScript.RegisterClientScriptBlock(Me.GetType(), "ClientScript", "alert ('choose date!')", True)
Exit Sub
End If
Dim DatumImport As Date = CDate(DdllDatum.SelectedValue.ToString)
Dim dt As New DataTable()
dt.Columns.AddRange(New DataColumn(4) {New DataColumn("Name_old", GetType(String)),
New DataColumn("Name_new", GetType(String)),
New DataColumn("userUpdate", GetType(String)),
New DataColumn("DateUpdate", GetType(Date)),
New DataColumn("DatumImport", GetType(Date))})
For i As Integer = 1 To GridTrx.Rows.Count - 1
Dim cb As CheckBox = DirectCast(GridTrx.Rows(i).Cells(0).FindControl("chkRow"), CheckBox)
If cb.Checked Then
Dim novi As TextBox = DirectCast(GridTrx.Rows(i).Cells(0).FindControl("txtUP"), TextBox)
Name_new = novi.Text.Trim
Name_old = GridTrx.Rows(i).Cells(1).Text.ToString
dt.Rows.Add(Name_old, Name_new, userUpdate, DateUpdate, DatumImport)
End If
Next
If dt.Rows.Count > 0 Then
UpdateUP(dt)
BindUP()
ClientScript.RegisterClientScriptBlock(Me.GetType(), "ClientScript", "alert ('Uspjesan update')", True)
Else
ClientScript.RegisterClientScriptBlock(Me.GetType(), "ClientScript", "alert ('Nije nista oznaceno za update')", True)
End If
End Sub