Click here to Skip to main content
15,893,663 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Please go through the codes below and explain "0".ToString();.

C#
DataTable DTLocal = new DataTable();
DTLocal.Columns.Add(new DataColumn("DocName"));
DTLocal.Columns.Add(new DataColumn("Status"));
DTLocal.Columns.Add(new DataColumn("RecDate"));
DTLocal.Columns.Add(new DataColumn("ID"));
DTLocal.Columns.Add(new DataColumn("ImpDocEndCode"));
DTLocal.Columns.Add(new DataColumn("chekStatus"));
int x;
for (int i = 0; i < grdBasicImpDoc.Rows.Count; i++)
{
        DataRow dra = DTLocal.NewRow();

        DropDownList status =                      (DropDownList)grdBasicImpDoc.Rows[i].Cells[3].FindControl("ddlStatus");
        int strStatus = status.SelectedIndex;
        TextBox RxpDat = (TextBox)grdBasicImpDoc.Rows[i].Cells[4].FindControl("txtRecDate");
        string strRecDat = RxpDat.Text;
        string strDocName = grdBasicImpDoc.Rows[i].Cells[2].Text;
        string strDocCod = grdBasicImpDoc.Rows[i].Cells[1].Text;
        string strID = grdBasicImpDoc.Rows[i].Cells[5].Text;
        dra["DocName"] = strDocName;
        dra["Status"] = strStatus;
        dra["RecDate"] = strRecDat;
        dra["ID"] = 0;
        dra["ImpDocEndCode"] = strDocCod;
        CheckBox cba = (CheckBox)grdBasicImpDoc.Rows[i].Cells[0].FindControl("ChkDelete");
        if (cba.Checked == true)
            x = 1;
        else
            x = 0;
        dra["chekStatus"] = x;
        DTLocal.Rows.Add(dra);
}

if (txtDocName.Text != "")
{

    DataRow dra1 = DTLocal.NewRow();
    dra1["DocName"] = txtDocName.Text;
    dra1["Status"] = "0".ToString();
    dra1["RecDate"] = "0".ToString();
    dra1["ImpDocEndCode"] = "0".ToString();
    dra1["ID"] = "0".ToString();
    dra1["chekStatus"] = 1;
    DTLocal.Rows.Add(dra1);
}
txtDocName.Text = "";
grdBasicImpDoc.DataSourceID = null;
grdBasicImpDoc.DataSource = DTLocal;
grdBasicImpDoc.DataBind();
Posted
Updated 26-Apr-13 18:30pm
v2
Comments
Sergey Alexandrovich Kryukov 27-Apr-13 0:45am    
Short answer is: this code sample is an example of how you should not write code.
—SA

1 solution

Hi,

its nothing, the person is converting string object back to string. The ToString was not at all required as "0" represents string object. the below code also works.
C#
dra1["Status"] = "0";
dra1["RecDate"] = "0";
dra1["ImpDocEndCode"] = "0";
dra1["ID"] = "0";
 
Share this answer
 
v2
Comments
Sumon562 27-Apr-13 0:41am    
Thank you Mr. Karthik Harve
Karthik Harve 27-Apr-13 0:43am    
Welcome.!! Happy Coding :-)
Sergey Alexandrovich Kryukov 27-Apr-13 0:44am    
This is correctly explained, but it needs a note: the code shown in question simply makes no sense. (I voted 4 this time.)

I would also tell OP that this is a counter-productive way of learning things. Anyone can pull any kind of trash from the Web, any amount of it. Why asking questions on any piece of junk? We should answer questions mostly on the code written by inquirers...

—SA
Karthik Harve 27-Apr-13 0:48am    
I totally agree with you.
Sergey Alexandrovich Kryukov 27-Apr-13 0:52am    
Thank you.
—SA

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