DATAGRID PROBLEM

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Savas Ates

    #1

    DATAGRID PROBLEM

    First When I Bind my datagrid It returns --Unisex-- value for my
    GENDER_NAME field. When I click Edit , Write UNI to update UNÝSEX value and
    Click Update button i catch

    UPDATE TBL_GENDER SET GENDER_NAME='Un isex' WHERE GENDER_ID=1
    with response.write ..

    Why it doesnt return me current value of my Text1 texbox item. What is the
    problem?




    <asp:DataGrid id="DataGrid1" style="Z-INDEX: 101; LEFT: 190px; POSITION:
    absolute; TOP: 195px"
    runat="server" AutoGenerateCol umns="False">

    <Columns>

    <asp:editcomman dcolumn edittext="Edit" canceltext="Can cel"
    updatetext="Upd ate" itemstyle-wrap="false"

    ItemStyle-Width="100px" />



    <asp:TemplateCo lumn>



    <EditItemTempla te >


    <asp:TextBox ID="Text1" Runat=server Text='<%#
    DataBinder.Eval (Container, "DataItem.GENDE R_NAME") %>'>

    </asp:TextBox>

    <asp:TextBox ID="Label1" Runat=server Visible=False Text='<%#
    DataBinder.Eval (Container, "DataItem.GENDE R_ID") %>'>

    </asp:TextBox>


    </EditItemTemplat e>


    </asp:TemplateCol umn>

    </Columns>
    </asp:DataGrid>



    Private Sub DataGrid1_EditC ommand(ByVal source As Object, ByVal e As
    System.Web.UI.W ebControls.Data GridCommandEven tArgs) Handles
    DataGrid1.EditC ommand

    Me.DataGrid1.Ed itItemIndex = e.Item.ItemInde x

    DataGrid1.DataB ind()





    End Sub







    Private Sub DataGrid1_Updat eCommand(ByVal source As Object, ByVal e As
    System.Web.UI.W ebControls.Data GridCommandEven tArgs) Handles
    DataGrid1.Updat eCommand





    Dim sorgu As String

    Dim strDestination As String = CType(e.Item.Fi ndControl("Text 1"),
    TextBox).Text

    Dim strID As String = CType(e.Item.Fi ndControl("Labe l1"), TextBox).Text

    Dim baglantim1 As New SqlClient.SqlCo nnection

    sorgu = "UPDATE TBL_GENDER SET GENDER_NAME='" & strDestination & "' WHERE
    GENDER_ID=" & strID

    Response.Write( sorgu)

    Response.End()

    End Sub




  • Chris Chilvers

    #2
    Re: DATAGRID PROBLEM

    On Sat, 29 Apr 2006 14:32:07 +0300, "Savas Ates" <in da club> wrote:
    [color=blue]
    >DataGrid1.Data Bind()[/color]

    This line looks suspect, calling databind will often end editing etc. It
    will also reset the viewstate and postback handling on the datagrid.

    Also double check that you don't call DataBind() every time you load the
    page, only when you first load the page. eg:

    If Not Page.IsPostBack () Then PopulateDatagri d()

    Where PopulateDatagri d() is the method that will query the database and
    call databind.


    [color=blue]
    >
    >sorgu = "UPDATE TBL_GENDER SET GENDER_NAME='" & strDestination & "' WHERE
    >GENDER_ID=" & strID
    >[/color]

    As a side note this code is potentualy unsafe due to sql injection, see
    http://www.codeproject.com/cs/databa...ionAttacks.asp for an
    explaination and solution.

    Comment

    Working...