<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default31.aspx.vb" Inherits="Default31" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script language="javascript" type="text/javascript">
function dopostb(rowid) {
document.getElementById('hdn').value = rowid;
document.getElementById('btn').click();
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:HiddenField ID="hdn" runat="server" ClientIDMode="Static" />
<asp:GridView ID="gv" runat="server" AutoGenerateColumns="false" GridLines="None">
<Columns>
<asp:BoundField DataField="COL1" />
<asp:TemplateField>
<ItemTemplate>
<asp:DropDownList ID="ddl" runat="server">
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
<div style="display: none">
<asp:Button ID="btn" runat="server" ClientIDMode="Static" />
</div>
</form>
</body>
</html>
============================================================
Partial Class Default31
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
Dim dt As New Data.DataTable
dt.Columns.Add("col1", GetType(String))
dt.Columns.Add("displayorder", GetType(Decimal))
dt.Rows.Add("ABC", 1)
dt.Rows.Add("PQR", 2)
dt.Rows.Add("XYZ", 3)
dt.Rows.Add("JKL", 4)
dt.Rows.Add("MNO", 5)
bindgrid(dt)
End If
End Sub
Private Sub bindgrid(ByVal dt As Data.DataTable)
ViewState("dt") = dt
gv.DataSource = dt
gv.DataBind()
End Sub
Protected Sub btn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn.Click
Dim dt As Data.DataTable = ViewState("dt")
Dim index As Integer = CType(gv.Rows(hdn.Value).FindControl("ddl"), DropDownList).SelectedIndex + 1
If CInt(dt.Rows(hdn.Value)("displayorder")) > index Then
dt.Rows(hdn.Value)("displayorder") = index - 0.5
Else
dt.Rows(hdn.Value)("displayorder") = index + 0.5
End If
dt.AcceptChanges()
Dim dv As Data.DataView = dt.DefaultView
dv.Sort = "displayorder asc"
dt = dv.ToTable
For i As Integer = 0 To dt.Rows.Count - 1
dt.Rows(i)("displayorder") = i + 1
Next
dt.AcceptChanges()
bindgrid(dt)
End Sub
Protected Sub gv_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gv.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
Dim ddl As DropDownList = e.Row.FindControl("ddl")
For i As Integer = 1 To CType(ViewState("dt"), Data.DataTable).Rows.Count
ddl.Items.Add(New ListItem With {.Text = i, .Value = i, .Selected = i = CInt(CType(e.Row.DataItem, Data.DataRowView)("displayorder"))})
Next
ddl.Attributes.Add("onchange", "dopostb(" & e.Row.DataItemIndex & ");")
End If
End Sub
End Class
=======================================================================
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script language="javascript" type="text/javascript">
function dopostb(rowid) {
document.getElementById('hdn').value = rowid;
document.getElementById('btn').click();
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:HiddenField ID="hdn" runat="server" ClientIDMode="Static" />
<asp:GridView ID="gv" runat="server" AutoGenerateColumns="false" GridLines="None">
<Columns>
<asp:BoundField DataField="COL1" />
<asp:TemplateField>
<ItemTemplate>
<asp:DropDownList ID="ddl" runat="server">
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
<div style="display: none">
<asp:Button ID="btn" runat="server" ClientIDMode="Static" />
</div>
</form>
</body>
</html>
============================================================
Partial Class Default31
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
Dim dt As New Data.DataTable
dt.Columns.Add("col1", GetType(String))
dt.Columns.Add("displayorder", GetType(Decimal))
dt.Rows.Add("ABC", 1)
dt.Rows.Add("PQR", 2)
dt.Rows.Add("XYZ", 3)
dt.Rows.Add("JKL", 4)
dt.Rows.Add("MNO", 5)
bindgrid(dt)
End If
End Sub
Private Sub bindgrid(ByVal dt As Data.DataTable)
ViewState("dt") = dt
gv.DataSource = dt
gv.DataBind()
End Sub
Protected Sub btn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn.Click
Dim dt As Data.DataTable = ViewState("dt")
Dim index As Integer = CType(gv.Rows(hdn.Value).FindControl("ddl"), DropDownList).SelectedIndex + 1
If CInt(dt.Rows(hdn.Value)("displayorder")) > index Then
dt.Rows(hdn.Value)("displayorder") = index - 0.5
Else
dt.Rows(hdn.Value)("displayorder") = index + 0.5
End If
dt.AcceptChanges()
Dim dv As Data.DataView = dt.DefaultView
dv.Sort = "displayorder asc"
dt = dv.ToTable
For i As Integer = 0 To dt.Rows.Count - 1
dt.Rows(i)("displayorder") = i + 1
Next
dt.AcceptChanges()
bindgrid(dt)
End Sub
Protected Sub gv_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gv.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
Dim ddl As DropDownList = e.Row.FindControl("ddl")
For i As Integer = 1 To CType(ViewState("dt"), Data.DataTable).Rows.Count
ddl.Items.Add(New ListItem With {.Text = i, .Value = i, .Selected = i = CInt(CType(e.Row.DataItem, Data.DataRowView)("displayorder"))})
Next
ddl.Attributes.Add("onchange", "dopostb(" & e.Row.DataItemIndex & ");")
End If
End Sub
End Class
=======================================================================
No comments:
Post a Comment